Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
241 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
426 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
70 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
241 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
105 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
419 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 ...
6
votes
3answers
830 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
178 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
307 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
259 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
148 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
149 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
2k 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
3k 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
44 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
404 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
235 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
337 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
369 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
125 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
138 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
95 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
789 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
151 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
310 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
578 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
6k 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
0answers
568 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
489 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
280 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
576 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 ...
7
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
209 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
3k 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
885 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
2answers
7k 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
3k 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
57 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
189 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
322 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
383 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
324 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 ...