Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
0answers
13 views

custom camera feed on fedora when using zoom.us

zoom work conferences became very popular lately. I saw some of my colleagues (who have macOS) use snap camera in zoom, so I tried looking for a goofy camera I can use as well on linux (fedora 29). I ...
1
vote
4answers
80 views

Reading from stderr in c

This is my c program read from stderr i write #include <uninstd.h> #include <stdio.h> int main(void) { char buff[3]; read(2, buff, sizeof(buff)); printf("%s", buff"); return 0; } My ...
0
votes
0answers
21 views

How can i control shell via stdin descriptor [duplicate]

I found out that launching, for example, sh and then piping command into its stdin descriptor does not affect opened sh anyhow. Why? How can i bypass it? How to reproduce: Launch sh In other ...
0
votes
1answer
23 views

Suppress sftp's info and errors but show progress

I have this sftp -q my_host:my_dir 1>/dev/null 2>&1 <<EOF some_command some_command some_command some_command put foo bar some_command exit EOF This suppresses: banner ...
0
votes
1answer
30 views

How to correctly use strace -e read=fd option?

I'm trying to monitor read activity on a particular file descriptor in a running process. Here is the C++ test bench I'm testing various solutions on: #include <fcntl.h> #include <unistd.h&...
-1
votes
1answer
110 views

What does file descriptor have to do with process table?

I have an interest in Operating Systems. So I am reading the xv6 book to understand Operating Systems. This is my first book on the subject. I read a line I couldn't understand. Internally, the xv6 ...
0
votes
0answers
47 views

Can kernel guarantee that POSIX close frees the descriptor?

Linux developers argue that it's pointless to retry close operation in case of an error, since the kernel "always releases the file descriptor early" (emphasis mine). While in general fildes state ...
0
votes
0answers
60 views

Is it guaranteed freshly opened `/dev/fd/3` always reads from start?

This is a Linux-specific question. The bash script is: echo foo > "a.txt" exec 3<"a.txt" cat /dev/fd/3 cat /dev/fd/3 cat /dev/fd/3 Output: foo foo foo All these cats display the content of /...
4
votes
1answer
36 views

bash: use different input streams for loop condition and body

i have a script with a while loop like this: while IFS= read -r name; do {body} done < names.txt the loop condition needs to read names from a file, but {body} needs to read from stdin; the ...
2
votes
2answers
76 views

Redirect stdout to command-A if success else stderr to command-b. While avoiding using temporary files

I have a command that writes to stdout when it is happy and stderr when it's not. I want to check the exit status of the command and do something with either stdout or stderr. if ! command >/tmp/...
2
votes
2answers
172 views

Startx as non-root user via SSH

I have a remote VM running Ubuntu 1804 and would like to run VNC. I am using x11vnc, which requires an X server to be running. Currently, I'm connected through SSH. The VM has an Nvidia card, and ...
4
votes
0answers
84 views

Bring back a deleted file without copying its content [duplicate]

As long as there is an open file descriptor pointing to a file, I can bring it back with cp like this: # Open for reading exec 3< file # Delete rm file # Bring it back cp /proc/self/fd/3 file ...
2
votes
2answers
55 views

Better method to get a side-value from awk

I have a script whose main purpose is to gather some information and output it in a table. The primary part is an awk script: awk ' { # do some stuff, including calculating dwt ...
3
votes
3answers
135 views

Communication between two file descriptors (clients)

I am following this document I struggle to wrap my head around file descriptors and how I could read data from one, process it and then send to another. As a server I need to be able to accept ...
8
votes
1answer
382 views

Why bash redirection to a file happens in append mode

given this snippet: exec 3>f echo foo >&3 echo bar >&3 cat f # returns foo bar Why is bash appending to f? Am I missing something?
0
votes
1answer
46 views

Cannot cat .pem file inline as -i option to ssh

I am getting this error: Warning: Identity file /dev/fd/63 not accessible: Bad file descriptor. when running this command: ssh -Y 'root@ec2-54-xxx-94-xxx.us-west-2.compute.amazonaws.com' -i <(...
-1
votes
1answer
67 views

Shell fails to find file descriptor file when `cat`ing it [duplicate]

I created a TCP socket and tried to examine its file descriptor. I can list it without a problem: [/proc/24846/fd]$ ls -al 11 lrwx------ 1 danb danb 64 10-Sep-19 22:58 11 -> 'socket:[38186892]' ...
0
votes
4answers
178 views

How to pipe fd 3 to consumer instead of fd1 / fd2

I was hoping to do something like this: echo 'foo' >&3 3| cat Basically, I want to write 'foo' to 3, and then only pipe the data in 3 to cat. But the above doesn't work, I get: bash: 3: ...
0
votes
1answer
373 views

Set-UID Capability Leak Attack

I have a C program to demonstrate the capability leak attack regarding set-uid. // cap_leak.c #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> ...
16
votes
4answers
3k views

Why should fork() have been designed to return a file descriptor?

On his web page about the self-pipe trick, Dan Bernstein explains a race condition with select() and signals, offers a workaround and concludes that Of course, the Right Thing would be to have fork(...
0
votes
1answer
71 views

How to work with file descriptors stored in variables?

For example, if I assign TWO=2 ...the following fails (with date: invalid date '2'): date >> logfile $TWO>&1 Of course, I can always do eval "date >> logfile $TWO>&1" ...
0
votes
0answers
45 views

File descriptors potential conflict

Context I'm processing data stored into files using a sequence of command line tools. In order to automate this process, I wrote a bash script chaining theses tools, the result of each tool being fed ...
0
votes
0answers
64 views

Understanding anonymous pipe ID

I'm currently debugging a system which has a resource leak. It seems that we have too many pipse open. When I go the my /proc/PROC_ID/fd I see the list of pipes l-wx------ 1 root root 64 Jun 30 12:32 ...
0
votes
0answers
43 views

Separate stdout of an application

I have an application that takes a few command line parameters, then prints some text to the terminal, then starts writing data to a file. It has a parameter I can use to define the file name to write ...
2
votes
2answers
354 views

Flush the pipe/printf buffers externally for already running process with known PID

I am writing a data logging app, all programs are started like: ./program > out.bin The data collector periodically pools the stdout output files and reads the data. The issue is that the IO ...
1
vote
1answer
272 views

How to source inline text

When you are creating tutorials online for people to use in a single terminal sometimes it's nice to source inline code...however none of these worked as I would expect. I would expect foo to be "bar" ...
0
votes
1answer
60 views

Process substitution to script in order to monitor iotop

I am actively trying to get the output of the iotop for monitoring. As you know, the iotop is interactive, meaning that once started, it'll provide live updates on disk usage on the system. I'm ...
-1
votes
1answer
369 views

hive + what is the meaning of nofile and nproc

regarding to hive in hadoop cluster what is the meaning of the following hive - nofile 30000 hive - nproc 18000 the file: more /etc/security/limits.d/hive.conf # Licensed to the Apache ...
0
votes
1answer
282 views

Difference between file descriptor and soft/hard link

If soft link and hard link are pointer to a file. And file descriptor is a file handle pointing to an open file. Then what exact difference is between the two if both of them are a kind of pointer ...
0
votes
0answers
19 views

Locale does not work with “file” command output

I have some JPEG files with Description metadata I added in MAC OS. exiftool (in MAC) displays them in correct locale. I copied those files to a Raspbian OS. From command line or bash script ...
0
votes
2answers
137 views

What happens when redirecting with 3>&1 1>/dev/null?

I'm playing around with file descriptors to better grok them and I'm failing to understand the following. $ grep "..." 3>&1 1>/dev/null 1 12 13 123 321 3 The above does not show in the ...
2
votes
1answer
215 views

Understanding pipes and redirections in dash

Someone asked how to pass the output of two commands as files to another command and they got the answer below. ( cmd1 | ( cmd2 | ( main_command /dev/fd/3 /dev/fd/4 ) 4<&0 ) 3<&0 ) I ...
1
vote
1answer
256 views

Understanding File Streams and File Descriptors

For extra context, I asked this question earlier, and thought I understood things, but not anymore. I know that echo ignores stdin. I know that stdin, stderr and stdout exist and, in this context, I ...
1
vote
2answers
604 views

exec command in bash loop for webscrapping

Here is a simple script which is curling https://unix.stackexchange.com/ and storing the result into an array, which is working fine. #!/usr/local/bin/bash [ -f pgtoscrap ] && { rm pgtoscrap; ...
1
vote
1answer
106 views

File Descriptors and Redirection

Several resources state the file descriptor 0 is connected to the keyboard. I have learned that echo does not receive input from stdin (or 0). This feels contradictory to me. When I run echo foo I'm ...
1
vote
1answer
45 views

Redirection to named file descriptor buggy inside functions

Bash has a feature where it will pick a file descriptor number for you and assign it to a variable. $ exec {fd}>foo.txt $ echo "$fd" 11 $ echo "bar" >&$fd $ cat foo.txt bar This feature ...
1
vote
1answer
133 views

Why do I need 'exec' if 'while read' can open a 'File Descriptor'

I want to read a file line by line using bash, tail and using a diferent file descriptor. all the guides use this method: method 1: echo 1111111 > z.txt exec {newFD}< <(tail -f -c +0 "z.txt"...
0
votes
0answers
34 views

Monitoring data flow to /dev/null for a given process

I have a process which reads out data from a custom PCI-e device using a custom driver. The program takes a file descriptor as an argument and writes the raw data to it. I would like to test the data ...
0
votes
1answer
1k views

Maximum value for /proc/sys/fs/file-max

Today my server crashed with Too many open files in system: but I already have high values, what is a maximum value for this? I feel like there aren't good results on google for this, explaining ...
2
votes
1answer
165 views

concurrent processing in bash using process expansion, and redirection

Apart from possible races that have to be controlled by using proper synchronisation, it's possible in bash to feed a data source concurrently into multiple pipelines and collect all their outputs ...
3
votes
3answers
441 views

tee into different variables

From the bash code command1 | tee >(command2) | command3 I want to capture the output of command2 in var2 and the output of command3 in var3. command1 is I/O-bound and the other commands are ...
0
votes
0answers
65 views

Is a mmaped file considered an open file in linux/unix?

Hi I feel confused about open file and mmapped file. I know that if a file is accessed using system call such as read/write will return a file descriptor, and be considered as an open file? How about ...
0
votes
1answer
343 views

Why is my files “last modified” timestamp only showing the year with the 'ls' command? [duplicate]

I'm building a java service that modifies the "Last Modified" field of some of the files it works with. The service keeps copies of files in a folder, it periodically checks a database for changes, ...
3
votes
1answer
434 views

lsof versus /proc/$PID/fd versus ulimit -n

I am trying to find the reason why my long-running app sometimes busts the maximum open file descriptor limit (ulimit -n). I would like to periodically log how many file descriptors the app has open ...
1
vote
0answers
264 views

Listen in to data read from file descriptor to ttyS

I have a serial device under /dev/ttyS0 and an application that is reading from the serial device (but not writing to it). I wanted to listen in to the data that is coming in on the serial device but ...
3
votes
2answers
242 views

How to periodically check if STDIN is open?

Some programs will exit when their STDIN is closed. Those that do this work nicely with Erlang/Elixir supervision via "ports". For those that don't, the Elixir docs suggest this wrapper script: #!/...
6
votes
2answers
2k views

Safest way to force close a file descriptor

Sometimes you need to unmount a filesystem or detach a loop device but it is busy because of open file descriptors, perhaps because of a smb server process. To force the unmount, you can kill the ...
0
votes
1answer
163 views

Multiple fifos over SSH

Shell script allow multiple file descriptors (up to 9 for POSIX compliance, but even more for bash): $ install -m 755 /dev/stdin /tmp/test <<\EOF #!/bin/sh echo hi1 >&1 echo hi2 >&...
2
votes
1answer
66 views

Why the output of ls is different for the same directory /dev/fd/ based on the method of referencing this directory?

cd /dev/fd/; ls Gives me output that I expect: 0 1 2 255 But: ls /dev/fd/ Gives different output that I don't expect: 0 1 2 3 Why? What happens here? What happened to file descriptor 255? ...
0
votes
0answers
373 views

Cannot pass argument through /proc/<pid>/fd/0

I have written a basic C++ program as such: #include <sstream> #include <unistd.h> #include <cstdio> #include <iostream> int main(void) { int foo; std::cin >> foo; ...

1
2 3 4 5 6