The tag has no wiki summary.

learn more… | top users | synonyms

23
votes
4answers
4k views

When would you use an additional file descriptor?

I know you can create a file descriptor and redirect output to it. e.g. exec 3<> /tmp/foo # open fd 3. echo a >&3 # write to it exec 3>&- # close fd 3. But you can do the same ...
14
votes
2answers
1k views

Portability of “> /dev/stdout”

Occasionally I need to specify a "path-equivalent" of one of the standard IO streams (stdin, stdout, stderr). Since 99% of the time I work with Linux, I just prepend /dev/ to get /dev/stdin, etc., ...
12
votes
3answers
3k views

Understanding /dev and its subdirs and files

$ ls -l /dev/stdin /dev/fd/0 lrwx------ 1 tim tim 64 2011-08-07 09:53 /dev/fd/0 -> /dev/pts/2 lrwxrwxrwx 1 root root 15 2011-08-06 08:14 /dev/stdin -> /proc/self/fd/0 $ ls -l /dev/pts/2 ...
11
votes
2answers
2k views

What happens when I close() a file descriptor?

I am trying to get the whole picture with file descriptors. Say I have process1 which initially has these file descriptors: _process1_ | | | 0 stdin | | 1 stdout | | 2 stderr | ...
11
votes
3answers
702 views

Practical use for moving file descriptors

According to the bash man page: The redirection operator [n]<&digit- moves the file descriptor digit to file descriptor n, or the standard input (file descriptor 0) if n is ...
11
votes
2answers
193 views

Output order with process substitution

This is what I usually do to run grep and wc on a file without having to scan it twice <file.txt tee >(grep LITERAL) >(wc -l) >/dev/null However, this yields EXEC LITERAL 32 ...
10
votes
2answers
399 views

Order of redirections

I don't quite understand how the computer reads this command. cat file1 file2 1> file.txt 2>&1 If I understand, 2>&1 simply redirect Standard Error to Standard Output. By that ...
9
votes
4answers
3k views

How can same fd in different processes point to the same file?

Say I have process 1 and process 2. Both have a file descriptor corresponding to the integer 4. In each process however the file descriptor 4 points to a totally different file in the Open File Table ...
9
votes
1answer
6k views

File descriptors & shell scripting

I am having a very hard time understanding how does one use file descriptors in shell scripts. I know the basics such as exec 5 > /tmp/foo So fd 5 is attached to foo for writing. exec 6 < ...
7
votes
3answers
606 views

How can a log program continue to log to a deleted file?

From the Unix Power Tools, 3rd Edition: Instead of Removing a File, Empty It section: If an active process has the file open (not uncommon for log files), removing the file and creating a new ...
7
votes
2answers
4k views

Execute command in remote active terminal

Suppose you have a terminal emulator (T1) open with a PID of 6350. From another terminal, type this command (C1): echo "ls\n" > /proc/6350/fd/0 This writes ls and the new line in T1 but does ...
7
votes
1answer
124 views

stderr over ssh -t

This sends output to STDERR, but does not propagate Ctrl+C (i.e. Ctrl+C will kill ssh but not the remote sleep): $ ssh localhost 'sleep 100;echo foo ">&2"' This propagates Ctrl+C (i.e. ...
6
votes
2answers
2k views

What's the purpose of the first argument to select system call?

From man select int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); nfds is the highest-numbered file descriptor in any of the three ...
6
votes
2answers
8k views

Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1

Just looking for the difference between 2>&- 2>/dev/null |& &>/dev/null >/dev/null 2>&1 and their portability with non-Bourne shells like tcsh, mksh, etc.
6
votes
2answers
843 views

file descriptor vs. file name

I was wondering what differences and relations are between file descriptors and file names. Are they all used to access files? If yes, in the same way? For example, /dev/fd/0, /dev/stdin, and ...
5
votes
2answers
225 views

Portability of file descriptor links

I've always wondered this but never took the time to find out, so I'll do so now - how portable is the usage shown here of either /proc/$$/fd/$N or /dev/fd/$N? I understand POSIX guarantees /dev/null, ...
5
votes
1answer
2k views

What is the file descriptor 3 assigned by default?

$ ls -og /proc/self /proc/self/fd lrwxrwxrwx 1 64 Jun 18 11:12 /proc/self -> 32157 /proc/self/fd: total 0 lrwx------ 1 64 Jun 22 2012 0 -> /dev/tty1 lrwx------ 1 64 Jun 22 2012 1 -> ...
5
votes
1answer
2k views

How to circumvent “Too many open files” in debian

If I want to see all relevant log files of my apache2 server at once, I use tail -f /var/kunden/logs/*log /var/kunden/logs/*log /var/log/apache2/*log |grep -v robots|grep -v favicon But since those ...
5
votes
1answer
97 views

Replacing stdout with stderr

Is it possible to redirect the output from a command to replace the text sent to stdout with the text from stderr? $ ./script this line is redirected to stdout this line is redirected to stderr $ ...
5
votes
1answer
781 views

Limits on the number of file descriptors

I'm trying to install 389-ds, And it gives me this warning : WARNING: There are only 1024 file descriptors (hard limit) available, which limit the number of simultaneous connections. I understand ...
5
votes
2answers
68 views

“command | less” vs “less <(command)”

A common "idiom" for viewing large amounts of command output is to pipe it to less, via command | less. However, it's also possible (perhaps only in bash, haven't tested in other shells) to use the ...
5
votes
1answer
425 views

Why does reading from two connected pty's cause an infinite loop?

I want to fake a gsm modem for testing a program. I want the program to send AT-codes to me and that I can answer it back, kind of a VirtualSerialPort. But for some reason the data written from the ...
5
votes
0answers
99 views

How can different file descriptors point to the same file in open file table? [duplicate]

Possible Duplicate: How can same fd in different processes point to the same file? I have a hard time grasping the two ideas of File Descriptor Table and Open File Table. Open File Table ...
4
votes
3answers
846 views

Something's special about /dev/fd/3

I've been trying to learn about file descriptors. When I type "ls -l /dev/fd/" I get lrwx------ 1 me users 64 May 2 16:02 0 -> /dev/pts/5 l-wx------ 1 me users 64 May 2 16:02 1 -> ...
4
votes
2answers
1k views

What is the referent of a file descriptor?

My understanding is that a file descriptor is an integer which is a key in the kernel's per-process mapping to objects such as open()ed files, pipes, sockets, etc. Is there a proper, short, and ...
4
votes
2answers
248 views

Process substitution from curl to bash as root

I'm trying to run a script from URL as root with this command: sudo bash <(curl -s http://copy.com/gLVZIqUubzcS/popcorn) But I'm getting this error: bash: /dev/fd/63: Aucun fichier ou dossier ...
4
votes
2answers
352 views

Cross-process dup on Linux

I'd like to dup a file descriptor running in an unrelated process on Linux. I know about sendmsg(2) and SCM_RIGHTS (e.g. ...
4
votes
1answer
33 views

How can I send reads and writes on a single file descriptor to different places?

I have a Linux executable foo that reads input from fd 0 and writes output to fd 0 (not fd 1). This works just fine for interactive use in the terminal. From the shell command line, how can I execute ...
4
votes
3answers
523 views

Please help explain this bash output redirection

This script was posted as answer to a Question. And I'm trying to work out what's going on. result=$( { { ssh host app-status >&3 3>&-; echo "$?" } | { until read ...
4
votes
1answer
243 views

Why doesn't the process substitution <() work with ssh -F

I have some vagrant virtual machines. To log into them I issue the vagrant ssh command. I want to log into them using regular ssh command. The vagrant ssh-config outputs the suitable config file $ ...
4
votes
1answer
430 views

Timestamp of socket in /proc/<pid>/fd

If I list /proc/<pid>/fd I see a number of entries for sockets. These entries have timestamps. At first I thought they were when the socket was created. But it doesn't always appear to be the ...
4
votes
2answers
475 views

How does file descriptor re-assigment work?

In a way this question is a extension of another question. In bash you can do pretty neat stuff with file descriptors. Like { command > /dev/null } 2>&1 | grep filter; to grep on stderr ...
4
votes
2answers
366 views

Does OpenBSD have a limit to the number of file descriptors?

What's the maximum number of file descriptors that a process can get on OpenBSD successfully? For example, there is an openfiles limit in login.conf(5) in OpenBSD. If I want to have as many file ...
3
votes
1answer
183 views

What does exec 3<&1 do?

I understand exec can do I/O Redirection on current shell level. but I only sees usage like exec 6<&0 # Link file descriptor #6 with stdin. # Saves stdin. exec 6>&1 # ...
3
votes
2answers
604 views

What sets a child's STDERR, STDOUT, and STDIN?

If a program runs fork() what sets standard streams STDOUT, STDIN and STDERR?
3
votes
1answer
70 views

What is the relationship between a program's output, standard output, and its file descriptors?

Let's assume that I am running wget which is downloading something. It's printing some text to my terminal and writes the downloaded data into a file. From a terminology point of view, what is the ...
3
votes
1answer
233 views

Significance of arrows symbols in duplicating/closing file descriptors under bash

I'm reading a book about Linux command line where author doesn't seem to follow the conventions in bash manual regarding arrows symbols used in redirection operations. Namely, he always uses left ...
3
votes
1answer
550 views

Parameretrize file descriptor number to open a tcp socket in shell script

I'm tried to parameretrize in a variable the file descriptor number to open a tcp socket using exec command but it failed. Only work correctly when file descriptor number is a constant. In the next ...
3
votes
0answers
62 views

Some puzzles of how to close file descriptors on sh or bash [duplicate]

Question 1. What will happen if we close a input file descriptor as if it is a output file descriptor? (or vice versa). For Example, $ exec 5<&2 $ exec 5>&- In my linux box, ...
2
votes
1answer
712 views

File descriptor and fork

When a child is forked then it inherits parent's file descriptors, if child closes the file descriptor what will happen ? If child starts writing what shall happen to the file at the parent's end ? ...
2
votes
2answers
398 views

stop pipe() opening stdin

I've currently got code that forks two processes. The first reads a http streaming radio and pushes the data down a pipe (opened with pipe() ) for the second process to read, decode and output to the ...
2
votes
2answers
154 views

Any way in Bash to write to a file every X seconds without closing it?

The hardware watchdog on my system needs a 0 written to /dev/watchdog at less than 60 seconds interval or it will fire. The file handle must be kept open however or the watchdog is then disabled. ...
2
votes
4answers
96 views

Can a running script identify the logging context?

Let us say I redirect the STDOUT, STDERR of a program to files. ./script.sh 1> output.log 2> error.log Can the running program find this out i.e. know the paths to these files?
2
votes
3answers
123 views

Redirecting only stderr to a pipe

This code snippet is from Advanced Bash Scripting Guide. # Redirecting only stderr to a pipe. exec 3>&1 # Save current "value" of stdout. ls -l 2>&1 ...
2
votes
2answers
3k views

What are the dangers of setting a high limit to max File Descriptors per process?

I'm working on an old legacy application, and I commonly come across certain settings that no one around cam explain. Apparently at some point, some processes in the application were hitting the max ...
2
votes
1answer
113 views

Why is it possible to refer to a closed stderr under bash?

I'd like to know why bash doesn't display an error message when we refer to a closed stderr. When it comes to other file descriptors, they have to be opened if we want to, for example, duplicate them. ...
2
votes
2answers
168 views

Where to place a Bash shell redirection for a command? [duplicate]

Possible Duplicate: Order of redirections Apart from the standalone exec >&2 to redirect the current shell's input and output are there any behavioral differences in the following ...
2
votes
1answer
72 views

closing the unwanted file descriptors

I am trying to understand how pipes work . This code snippet is from some website . So my understanding of the program goes like this : When we do pipe(fd) then fd[0]=3 and fd[0]=4 ( assuming only ...
2
votes
1answer
1k views

How to find speed of wlan interface?

I'm trying to find speed of network interface using file-descriptor. It's easy to do it for ethX, just calling cat /sys/class/net/eth0/speed. Unfortunately this method doesn't work with wireless ...
2
votes
2answers
435 views

Close all file descriptors in bash

Is there a way to close all the open file descriptors, without having an explicit list of them beforehand?