Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [file-descriptors]

The tag has no usage guidance.

0
votes
0answers
26 views

“Too many files” error, but no process exceeds maximum file limit [on hold]

I am trying to open a file in a C process of mine, but it fails, and I see a "Too many files" error. So I checked all of my processes for how many files they were using, and none of the processes in /...
0
votes
0answers
18 views

Monitoring data flow to /dev/null for a given process

I have a process which reads out data from a custom PCI-e device using a custom driver. The program takes a file descriptor as an argument and writes the raw data to it. I would like to test the data ...
0
votes
1answer
27 views

Maximum value for /proc/sys/fs/file-max

Today my server crashed with Too many open files in system: but I already have high values, what is a maximum value for this? I feel like there aren't good results on google for this, explaining ...
2
votes
1answer
61 views

concurrent processing in bash using process expansion, and redirection

Apart from possible races that have to be controlled by using proper synchronisation, it's possible in bash to feed a data source concurrently into multiple pipelines and collect all their outputs ...
3
votes
3answers
111 views

tee into different variables

From the bash code command1 | tee >(command2) | command3 I want to capture the output of command2 in var2 and the output of command3 in var3. command1 is I/O-bound and the other commands are ...
0
votes
0answers
29 views

Is a mmaped file considered an open file in linux/unix?

Hi I feel confused about open file and mmapped file. I know that if a file is accessed using system call such as read/write will return a file descriptor, and be considered as an open file? How about ...
0
votes
1answer
35 views

Why is my files “last modified” timestamp only showing the year with the 'ls' command? [duplicate]

I'm building a java service that modifies the "Last Modified" field of some of the files it works with. The service keeps copies of files in a folder, it periodically checks a database for changes, ...
2
votes
1answer
72 views

lsof versus /proc/$PID/fd versus ulimit -n

I am trying to find the reason why my long-running app sometimes busts the maximum open file descriptor limit (ulimit -n). I would like to periodically log how many file descriptors the app has open ...
1
vote
0answers
71 views

Listen in to data read from file descriptor to ttyS

I have a serial device under /dev/ttyS0 and an application that is reading from the serial device (but not writing to it). I wanted to listen in to the data that is coming in on the serial device but ...
4
votes
2answers
94 views

How to periodically check if STDIN is open?

Some programs will exit when their STDIN is closed. Those that do this work nicely with Erlang/Elixir supervision via "ports". For those that don't, the Elixir docs suggest this wrapper script: #!/...
5
votes
2answers
340 views

Safest way to force close a file descriptor

Sometimes you need to unmount a filesystem or detach a loop device but it is busy because of open file descriptors, perhaps because of a smb server process. To force the unmount, you can kill the ...
0
votes
0answers
70 views

Multiple fifos over SSH

Shell script allow multiple file descriptors (up to 9 for POSIX compliance, but even more for bash): $ install -m 755 /dev/stdin /tmp/test <<\EOF #!/bin/sh echo hi1 >&1 echo hi2 >&...
2
votes
1answer
26 views

Why the output of ls is different for the same directory /dev/fd/ based on the method of referencing this directory?

cd /dev/fd/; ls Gives me output that I expect: 0 1 2 255 But: ls /dev/fd/ Gives different output that I don't expect: 0 1 2 3 Why? What happens here? What happened to file descriptor 255? ...
0
votes
0answers
178 views

Cannot pass argument through /proc/<pid>/fd/0

I have written a basic C++ program as such: #include <sstream> #include <unistd.h> #include <cstdio> #include <iostream> int main(void) { int foo; std::cin >> foo; ...
0
votes
2answers
62 views

STDOUT + STDERR output … is there any difference between considering the output to be an empty string vs NULL

I'm writing some application code that is used to execute Linux shell commands, and it then logs the command details into an SQL database. This includes the output of STDOUT + STDERR (separately). ...
5
votes
1answer
188 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
24 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 ...
10
votes
4answers
2k views

Temporary folder that automatically destroyed after process exit

Can we use temporary folders like temporary files TMP=$(mktemp ... ) exec 3<>$TMP rm $TMP cat <&3 which will be destroyed automatically after this shell exit?
5
votes
2answers
198 views

Why doesn't sed -i work with /proc/PID/fd/FD

I have this file and fd: exec 88<>abc Why $ sed -i "s/cd/II/g" /proc/$$/fd/88 sed: couldn't open temporary file /proc/26194/fd/sedS1D1FT: No such file or directory but this work: $ cat /...
3
votes
1answer
667 views

Difference between ulimit, lsof, cat /proc/sys/fs/file-max

I've been getting java.io.IOException: Too many open files while running a Kafka instance and using one topic with 1000 partitions so I started investigating the file descriptors limits in my ec2 vm. ...
0
votes
1answer
54 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-...
3
votes
1answer
525 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 ...
5
votes
2answers
1k 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
82 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 ...
0
votes
1answer
401 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 ...
1
vote
0answers
29 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 ...
1
vote
1answer
44 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 ...
0
votes
0answers
183 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:...
0
votes
2answers
369 views

pass stdout fd to 'read' system call, but it still works fine [duplicate]

I pass 1(stdout)/2(stderr) to read system call but it still works fine. Then I pass 0(stdin) to write system call and find out it works too! int main(int argc, char** argv){ char buf[1024] = "...
-1
votes
2answers
48 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
0answers
25 views

send stdin to stderr for a time, then stop after timeout and discard: gnu textutils?

We have a very chatty application which says useful things during startup but then refuses to be quiet (useful logs are sent elsewhere). This interacts problematically with log rotation, snapshotting, ...
-1
votes
2answers
204 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
210 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
198 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
347 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
62 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
195 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
97 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
368 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
788 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
138 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
264 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
214 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
108 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
918 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
120 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
2k 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
37 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 &...