Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4
votes
1answer
369 views

Testing if a file descriptor is valid (for input)

In the question "Testing if a file descriptor is valid", a test is sought for testing whether a file descriptor is opened or not. The answers all focus on testing whether the file descriptor is ...
1
vote
1answer
65 views

A command wants file paths. How can I give it stdin for the “infile” and stdout for the “outfile”?

Consider a command like foo -in /path/to/infile -out /path/to/outfile, that you'd like to pass strings to rather than using temp files. It may be called a lot causing much disk access, or is related ...
7
votes
2answers
2k views

In Bash, what is file descriptor 255 for, can I use it?

I understand file descriptor (or file handler) is an file IO technique in Linux systems. I also know that each process has 3 standard streams (namely stdin, stdout and stderr) that are represented ...
0
votes
1answer
103 views

Number of file descriptors - pidstat

As mentioned here: On RHEL 7.x, below command: pidstat -C syslog-ng -v does not recognise -v option Alternative: There are two process 417880 & 417881 for syslog-ng: # ls /proc/`pidof syslog-...
4
votes
1answer
1k views

How copytruncate actually works? [closed]

we would like to understand copytruncate before rotating the file using logrotate with below configuration: /app/syslog-ng/custom/output/all_devices.log { size 200M copytruncate dateext ...
3
votes
3answers
8k views

How to display open file descriptors with thread id without using lsof command

How to display open file descriptors with thread id without using lsof? I know a similar question exists but the answer doesn't include thread details.
10
votes
4answers
10k views

Why can't I `tail -f /proc/$pid/fd/1`?

I wrote a simple script which echo-es its PID: #/bin/bash while true; do echo $$; sleep 0.5; done I'm running said script (it says 3844 over and over) in one terminal and trying to tail the ...
9
votes
1answer
24k views

Fixing ulimit: open files: cannot modify limit: Operation not permitted

I tested this on different GNU/Linux installations: perl -e 'while(1){open($a{$b++}, "<" ,"/dev/null") or die $b;print " $b"}' System A and D The first limit I hit is 1024. It is easily raised ...
17
votes
3answers
2k views

find out which file descriptors share the same “open file description”

If I do (in a Bourne-like shell): exec 3> file 4>&3 5> file 6>> file File descriptors 3 and 4, since 4 was dup()ed from 3, share the same open file description (same properties, ...
0
votes
1answer
119 views

How does the act of closing shared file descriptors with a write-blocked process cause it to unblock?

Given multiple processes, forked from a parent process with shared file descriptors (representing STDOUT/STDERR), if one of the processes writes to STDOUT and exceeds the ~64K buffer it will block (as ...
31
votes
1answer
91k 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 ...
2
votes
0answers
41 views

Get the path of song playing in VLC using python script

I am trying to get the path of song playing in VLC using python script. I have already find out the Process ID of vlc using pgrep -x vlc And I can also display the all file descriptors of vlc ...
0
votes
1answer
642 views

display the file descriptors of a process using python [closed]

How can I display the open file descriptors of a process in linux using python script? I tried using readlink /proc/PID/fd/* in python script but I am getting error. /bin/sh: 2: /fd/*: not found ...
5
votes
4answers
4k views

Why is there a “/dev/fd/63” in the output of “echo 123 >(cat)”?

$ echo 123 | cat 123 is doing what I expected, both commands run inside the same shell. But when I connect them with the >( ... ) expression, which connects the output of one command in the ...
1
vote
1answer
65 views

Why I can't see port opened by a process in file descriptors?

I have a rabbitmq management process running, which opens a port 15672, tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 5431/beam As you can see the process has a PID ...
10
votes
3answers
5k 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 one ...
0
votes
0answers
300 views

ss command: file descriptor information when using the -p option

In ss command, when using the -p option, this presumably provides info about the process (owner, pid an fd) root@Cassiopeia:~# ss -tap | tail -1 ESTAB 0 0 [2a0i:527:9981:8511:f64e:...
3
votes
1answer
4k 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 ...
17
votes
3answers
50k views

How to list the open file descriptors (and the files they refer to) in my current bash session

I am running in an interactive bash session. I have created some file descriptors, using exec, and I would like to list what is the current status of my bash session. Is there a way to list the ...
-1
votes
2answers
52 views

Shell script to match row number from one file and put it as comments in another file when match

I have two files. The content of both files has dynamic and generated by the system when required. The first file contains the meaning for specific row number as below : head simdb.txt MSISDN ...
0
votes
2answers
298 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: ...
0
votes
2answers
342 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 ...
32
votes
1answer
41k 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 < /...
16
votes
3answers
3k 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 ...
0
votes
1answer
279 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 ...
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: $ ...
2
votes
1answer
468 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 ...
10
votes
1answer
958 views

OS X, bash: less works on open file descriptors, cat doesn't

In a bash script I'm working on (which has to run on Ubuntu and OS X), I need to redirect the output of hundreds of commands to a file. Rather than appending &>... to all of them, I simply do ...
-3
votes
1answer
115 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 ...
3
votes
1answer
254 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 ...
11
votes
2answers
459 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
854 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
3answers
335 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
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
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
167 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 ...
55
votes
5answers
12k views

How portable are /dev/stdin, /dev/stdout and /dev/stderr?

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., ...
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
176 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 ...
189
votes
3answers
169k 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
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
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
495 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
250 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
394 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: ...