Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
197
votes
3answers
177k 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.
2
votes
2answers
4k views

What happens to file descriptors when the process is killed?

In my application I open a file, using the open() call. My questions are: Is the file automatically closed (as using the close() call on the returned file descriptor) if I kill the process? What ...
0
votes
0answers
64 views

In cron, /usr/bin/paplay does not display stderr

My PC's pulse audio dies whenever I open and close virtualbox windows in a certain situation. So I tried to monitor the audio state by crontab -e. Usually, in the commandline, $ paplay beep.wav &...
1
vote
1answer
678 views

Cannot get bash flock to work

I derived a sample bash script from what I have seen around, regarding bash flock function. I do: func() { 42>/home/foo flock -e 42 || exit 1 echo "hello world" sleep 5 } Then I ...
2
votes
1answer
3k views

Sharing file descriptors

If file descriptors are specific to each process (i.e. two processes may use the same file descriptor id to refer to different open files) then how is it possible to share transfer file descriptors (e....
0
votes
0answers
261 views

Creating an exact copy of a whole process?

fork() forks a process, but it will not copy all of its threads; nor will it create a clone of all its fds: the fds are shared between parent and child. I want a way of do a complete fork. So after I ...
2
votes
2answers
2k views

Why are file descriptors shared between forked processes?

When we fork() a process, the child process inherits the file descriptors. The question is, why? As I am seeing it, sharing the file descriptor is a headache when every process is trying to keep ...
2
votes
2answers
471 views

Why doesn't ulimit -n work when called inside a script?

This is very odd. I'm trying to set the ulimit to 60000 via my startup.sh: #!/bin/bash ulimit -n 60000 echo "Hello! File Descriptor set" I can execute this with ./startup.sh (755 file permissions) ...
0
votes
1answer
58 views

Can you seek to a filehandle owned by another process as root?

There is a method to seek with a filehandle in C, int fseek(FILE *stream, long offset, int whence); There is also a file in fdinfo for each file descriptor, cat /proc/self/fdinfo/2 pos: 0 flags: ...
0
votes
0answers
420 views

/var/log mounted as a tmpfs failing to get umounted on FreeBSD

I have /var/log mounted as a tmpfs, where log files are synced periodically to the disk by the cron on FreeBSD. The process is done by the rc script. I am mounting it like: mount -t tmpfs -o nosuid,...
2
votes
1answer
133 views

Does fd number of various shells fixed?

Let's say: xb@dnxb:/tmp$ echo 'ls -l /proc/$$/fd | grep a.sh' > a.sh; \ > while IFS='' read -r f; do \ > echo "$f"; "$f" a.sh; \ > done < <(tail -n +2 /etc/shells) /bin/sh lr-x------...
13
votes
2answers
28k 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 ...
0
votes
2answers
200 views

Does unix/linux maintain a list of all free file descriptors?

I am reading Linux System Programming by Robert Love and trying to understand the concept of file descriptors. He mentions that File descriptors start at 0 and go up to one less than this maximum ...
0
votes
1answer
1k views

How can a process have a higher open file descriptors limit than that set by the hard limit?

I am using Solaris 11 and it is my understanding that a non-privileged user can increase or decrease the soft limit of maximum open file descriptors while staying within the hard limit. It is also ...
0
votes
2answers
3k views

Redirection using file descriptors - specific example [duplicate]

I am reading this documentation which gives the following examples about redirection and file descriptors. ls > dirlist 2>&1 will direct both standard output and standard error to the ...
7
votes
1answer
4k views

Flock doesn't seem to be working

I've recently been trying to create a shell script for a minor project, and for some reason, the flock command isn't working for me properly. Whenever I invoke it in a subshell the atomic way and put ...
1
vote
1answer
30 views

If I replace files that are in use by a hung process and start a new process, will it use the new files or the old ones?

I am on Red hat GNU/linux 2.6.32-431.29.2.el6.x86_64. Recently - One of my process hung. This process was using few files from a directory - say DIR-1 . While process was in hung state, I moved ( ...
2
votes
2answers
116 views

How does 'eject' get processes to close file handles?

On my Mac, when I 'eject' a network-mounted share, my Mac presents me with the following message, and attempts to get processes to close open file handles and cleanly dismount the share. My question ...
75
votes
7answers
40k 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 ...
4
votes
1answer
965 views

Bash - Use automatic file descriptor creation instead of fifo

At the beginning, I created a small server with netcat and it worked well: #!/bin/bash PORT="1234"; startServer(){ fifo="fifo/$1"; mkfifo "$fifo"; connected="0"; netcat -q 0 -l -p ...
2
votes
1answer
170 views

How to pass pseudo-file to child program?

I am using Cygwin - no, don't close yet - and I am having trouble with the <() syntax. A program refuses to accept the file descriptor that I am passing it, but other programs will accept it fine. ...
1
vote
1answer
360 views

How to list file descriptors of any command before it finishes?

File descriptors can be easily listed by executing ls -l /proc/$PID_OF_RUNNING_OR_PAUSED_PROCESS/fd/. But the commmand has to be running or paused at time of listing in order file descriptors still ...
11
votes
1answer
2k 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 $ ...
3
votes
2answers
8k views

Bash redirection: append to a file descriptor (2>>&1)

I'm trying to append the output of a command (stdout and stderr) to an existing file. What I'm trying to do is something like this: command >>file 2>>&1 The problem is that 2>>...
1
vote
1answer
976 views

Effect on the shell pipe operator on stdin, stdout and stderr

When I create a pipe using the shell, for example: ls | cat What I know for sure is that the stdin for cat will be the stdout for ls (i.e. everything ls writes to its stdout, cat will read it ...
3
votes
1answer
5k views

File descriptor limits in /etc/system vs /etc/sysctl.conf vs /etc/security/limits.conf on Solaris

Let me explain first what I understood. In Solaris 10, rlim_fd_max and rlim_fd_cur in /etc/system set the hard and soft limits at the system level. And /etc/security/limits.conf sets the limits for ...
1
vote
2answers
337 views

Why does the cat command only read from the first file descriptor?

From the console, I've created 2 empty files, and I tried to read them simultaneously. $ echo -n '' | tee f1 > f2 $ cat f1 f2 $ cat <(tail -f f1) <(tail -f ./f2) On the other console I've ...
0
votes
1answer
673 views

What is using up file descriptors?

I have a problem where my application is crashing saying that there are too many open files. running lsof | wc -l it says that there are 3447067 open file descriptors however I can't find out what is ...
2
votes
1answer
78 views

Should the file descriptor be closed once used?

I am doing a project. But I found in the source code there are so many file descriptor left unclosed. The first glance of it, I thought this is not good. After I googled, someone says, if there are ...
0
votes
1answer
280 views

create a Virtual server in virtualmin: mailbox failed, Bad File Descriptor

I'm trying to create a Virtual server in virtualmin and everytime i click in create it displays an error : Creating mailbox for administration user .. .. mailbox failed : Failed to write to /home/...
8
votes
1answer
1k views

What am I supposed to use `O_PATH` for, and how?

I use a Linux 4.x-based distribution, and I've recently noticed the kernel's open() system call supports an O_PATH open flag. While the man page for it does have a list of system calls it could ...
6
votes
2answers
433 views

dash: Pipe STDIN to multiple commands and their output to STDOUT in defined order

At first I thought this answer was the solution, but now I think I need a temporary file as buffer. This works unreliably: #!/bin/sh echo 'OK' | { { tee /dev/fd/3 | head --bytes=1 >&...
1
vote
0answers
233 views

correct syntax for use of file descriptors with imagemagick

According to the ImageMagick manual, file descriptors are supported as of v.6.4.9-3. I am running v.6.9.7-4. However, I have been able to determine the correct syntax. Examples tried: convert 'xc:...
5
votes
2answers
1k views

Is there a simple test for anything printed on stderr in shell/Bash?

I'd like invoke a command inside a shell script for Continuous Integration purposes. Exit status 0 means succes, otherwise failure. I'm writing a wrapper script to run several commands and fail if any ...
1
vote
4answers
5k views

Is it possible to write to other file descriptors in C?

If I wish to redirect all stdout to a file, I would run my_prog 1> out If I wish to do the same for stderr, I would run my_prog 2> err However, I know that in shell there are other file ...
3
votes
1answer
2k views

Reading file descriptors

Content of a file named file testing 1 testing 2 Command tested exec 3<> ./tmp cat file 1>&3 3>&1 Outputs nothing. Why? I read my command as cat content in file, then read ...
1
vote
1answer
75 views

Providing additional descriptors to caller of script

My script does a lot of remote calls and output progress of a long operation on screen to STDOUT. I currently hide all of STDOUT and STDERR from my remote calls because i don'T want them to taint my ...
7
votes
1answer
2k views

What's the difference between setting open file limits in /etc/sysctl.conf vs /etc/security/limits.conf?

I've read two separate ways of increasing the allowed open file count (I'm attempting to modify for root, if it matters). One way is to update the settings in /etc/security/limits.conf with something ...
3
votes
1answer
224 views

Why does zsh open a file descriptor off by one?

I can open a file descriptor explicitly the normal way: $ ls -lh /dev/fd/ total 0 lrwx------ 1 tavianator users 64 Jul 10 11:06 0 -> /dev/pts/6 lrwx------ 1 tavianator users 64 Jul 10 11:06 1 ->...
2
votes
1answer
432 views

Why changing tty settings on one file descriptor affects another?

ECHO setting is enabled on stdin and stdout by default. But why if we disable ECHO on stdin, it is also disabled on stdout? They have two separate descriptors - 0 and 1, so why they are changed ...
2
votes
2answers
441 views

Max out file descriptors

I wish to write a script that will use up all of the available file descriptors on my Linux machine. I am unsure how exactly to do this, or if it is even possible? But I wish to use this script for a '...
1
vote
1answer
423 views

How does GnuPG outputs to console while stdout and stderr are both redirected to /dev/null

Example : bash$ gpg --batch --edit-key alice quit >/dev/null 2>&1 Secret key is available. pub 2048R/9F07612A created: 2017-06-20 expires: never usage: SCEA ...
3
votes
1answer
56 views

Why does moving forward switch the file system here?

If I navigate to a new, empty directory ~$ cd "`mktemp -d`" and mount a file system there /tmp/tmp.4MlNzMERSw$ sudo mount /dev/sda5 . and then try to list the files there, I don't see the files on ...
8
votes
2answers
16k 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 ...
3
votes
2answers
357 views

Difference between file and file descriptor linked to a file

I have a file which contains four lines: $ cat file First line Second line Third line Fourth line $ When I read this file four times, then I always read the first line which is an expected result: ...
2
votes
1answer
1k views

What are file descriptors other than 0, 1 and 2

I am trying to understand the logs of sysdig. It mentions there file descriptors other than 0 (standard input), 1 (standard output), 2 (standard error); file descriptors such as 3, 6, 7, -2 are listed....
0
votes
0answers
1k views

Writting to a Tun/Tap interface

Recently I've been using a tun interface to redirect the Internet traffic through my methods. To do so, I followed this tutorial. My idea is to have a program which receives the IP packets that go to ...
3
votes
1answer
142 views

File descriptor duplication behaviour

I have this file: 1 2 3 4 When I run paste in this manner paste - - <file this results 1 2 3 4 so far so good, standard input(redirected from file) is passed twice to paste ...
29
votes
3answers
5k 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 ...
1
vote
1answer
159 views

Is there a way to send a string to the STDIN of an existing PID in AIX?

To give you some context, there's a ksh script running in AIX that contained a rm file.txt instruction - the problem is that the file, being owned by a shared group but by other user, made the script'...