Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
345 views

Is a file descriptor ever NOT open?

Of course a file can be open, or not open. However, a file descriptor by definition refers to an open file (right?). (Well, except when it refers to something besides a file, like a pipe or what ...
0
votes
2answers
299 views

How to I tail the STDOUT of a cat command [duplicate]

Let's say that I start a cat process to wait for some input. e.g., $ cat > out.log In another terminal, I can identify its PID and feed data into its File Descriptor 0 (zero = STDIN), like this: ...
10
votes
3answers
2k views

Named pipes, file descriptors and EOF

Two windows, same user, with bash prompts. In window-1 type: $ mkfifo f; exec <f So bash is now attempting to read from file descriptor 0, which is mapped to named pipe f. In window-2 type: $ ...
0
votes
1answer
282 views

using fifo for daemons

While studying from Richard Stevens' book Unix network programming, I came across the following lines that speak about using FIFO between a client and a server. Client processes are started and ...
2
votes
1answer
472 views

Trap and collect script output, “input file is output file” error?

I need to upload the output of the current script, so I added a trap and set -ex, e.g #!/bin/bash exec &> /tmp/error.log trap 'cat /tmp/error.log; curl http://127.0.0.1/error.php?hostname=$(...
0
votes
1answer
77 views

Why `tail -f data_log | grep keyword` within tmux session could lead to hard disk exhaustion?

The scene is like, yesterday I need to check some api bug. So I logged into the log server. I opened up a tmux session, so I can reconnect to my work later. I typed in tail -f data_log | grep keyword ...
3
votes
1answer
258 views

How can we disconnect a file descriptor from any file?

In bash we can create a connection between a file descriptor and a file, e.g. by exec > /path/to/myfile which connects fd 1 to the file. I was wondering how we can disconnect a fd from any file ...
-3
votes
1answer
117 views

Does a shell automatically connect file descriptors 0, 1 and 2 to its controlling terminal?

From The Linux Programming Interface In an interactive shell, these three file descriptors 0, 1 and 2 normally refer to the terminal under which the shell is running. Does "the terminal ...
11
votes
2answers
461 views

What's the lifespan of a file descriptor?

As described here, redirections use open() to write to a file. There's an inner (?) file descriptor created in the shell, and then used when needed. Is the inner descriptor created for the whole ...
7
votes
3answers
856 views

Do file descriptors optimise writing to files?

Is it equivalent to have commands print to a file directly, as opposed to writing to a file descriptor? Illustration Writing to file directly: for i in {1..1000}; do >>x echo "$i"; done ...
0
votes
1answer
208 views

Change stdout/stderr output device

By default if we run foo(){ echo "myfoo" } it will go to stdout. My question is, for a bash script or function, is there a programmatic way to change the device so that commands don't ...
0
votes
3answers
339 views

Read from file descriptor and write to stdout

I want to prepend something to each line of output in a script, for every command. I was thinking of doing something like this: rm foo mkfifo foo exec 3<>foo cat <&3 | while read line;...
0
votes
1answer
282 views

mapping of ioctl to its definition

The prototype of ioctl in linux driver modules is int ioctl(struct inode *i, struct file *f, unsigned int cmd, unsigned long arg); or long ioctl(struct file *f, unsigned int cmd, unsigned long arg);...
1
vote
1answer
169 views

Problem with system wide file handle count

Trying again with a shorter, more focused question. Please note this is NOT the usual "why is file-nr reporting a lower number than I expect" question. I have the opposite problem. A Linux 2.6 system ...
4
votes
2answers
1k views

Does POSIX standardize the file descriptor numbers?

Does POSIX mandate that stdin is 0, stdout is 1 and stderr is 2 or is this only a convention? Do other systems diverge from that convention or is it a safe assumption?
1
vote
0answers
177 views

Bind an existing process to a socket

I want to bind an existing process to a socket listenning on a specific port with nc and send input to it (a python interactive shell, an editor...) whatever process, just send a pid and bind it, ...
1
vote
1answer
3k views

Sockets and File Descriptors

As far as I have seen, a socket creates 3 file descriptors in the /proc//fd folder, STDIN, STDOUT and STDERR. When I input in one socket, it should out the other socket, in a raw-TCP connection, but ...
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
56 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
504 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
2k 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
251 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 ...
1
vote
2answers
1k 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
400 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
54 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
397 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
128 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------...
0
votes
2answers
157 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 ...
1
vote
1answer
29 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
104 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 ...
4
votes
1answer
869 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
158 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
345 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 ...
1
vote
1answer
738 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
2answers
7k 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>>...
2
votes
1answer
639 views

How do I create a default file association in Debian with Gnome?

I'm using Debian Jessie 64-bit with Gnome 3.14.1. My TIF image files are opening by default in the PDF Viewer, don't ask why. In Nautilus, I right-click on the file, click Open With|Other Application....
4
votes
2answers
541 views

cryptsetup - how does it print prompt bypassing stdout/stdin redirection?

I just noticed that no matter which cryptsetup FDs are forwarded to /dev/null it still shows prompt for password. For example this still shows prompt: cryptsetyp luksOpen /dev/sdXY name >/dev/null ...
1
vote
2answers
295 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
635 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 ...
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 ...
1
vote
0answers
223 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:...
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 ...
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 ...
9
votes
3answers
8k views

Writing to stdin of a process

As far as I understand if i type the following... python -i ... the python-interpreter will now read from stdin, behaving (obviously) like this: >>> print "Hello" Hello I would expect ...
1
vote
4answers
4k 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
1k 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
65 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 ...
6
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
203 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 ->...