Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
25 views

How to bypass pipe detection? [duplicate]

A question at stackoverflow has answers that show the following way of detecting if standard output is a pipe: if [ -t 1 ] ; then echo terminal; else echo "not a terminal"; fi The -t flag ...
glibg10b's user avatar
  • 368
1 vote
0 answers
48 views

Is there a known linux kernel bug with two threads incorrectly getting back the same file descriptor number?

I've got a multithreaded program in which a sem_open with O_CREAT occasionally fails with EBADF. This is on an ARM linux 4.9.88, from NXP, on an embedded device. It is very difficult to reproduce, ...
Matt DiMeo's user avatar
1 vote
1 answer
77 views

Capturing output from a bash function without using a subshell [closed]

I have a bash script listening on a pipe for commands. When it sees a command it runs it. However, I would like it to support the "sideloading" of bash functions that can be called at a ...
nopcorn's user avatar
  • 9,609
0 votes
1 answer
48 views

How to identify what file descriptors are associated to STDIN, STDOUT etc

I seem to remember some command or envvar that tells you this. I'd like basically something that executed on terminal, for instance, give you echo $STDIN /dev/tty echo $STDOUT /dev/tty fdescribe 0 or ...
Whimusical's user avatar
1 vote
1 answer
135 views

What is file descriptor 47 used for?

I have noticed that when I run ls /proc/self/fd I get the following output: 0 1 2 3 47 Obviously, 0, 1 and 2 are the descriptors for stdin, stdout and stderr, respectively, and 3 is the ...
DarkAtom's user avatar
  • 111
1 vote
2 answers
93 views

How do I use a nonstandard file descriptor for reading a file into an array with mapfile?

mapfile -t -u 7 arr < textfile gives me bash: mapfile: 7: invalid file descriptor: Bad file descriptor Other, more verbose, methods of reading files line-by-line do allow for such descriptor, e.g. ...
John Smith's user avatar
0 votes
2 answers
89 views

Where output of Bash itself goes?

For one script I wanted to redirect "[1] 00000" message that appears my shell after sleep 100& command. I don't need that anymore, but while struggling with that problem, I start ...
Basher's user avatar
  • 1
1 vote
0 answers
60 views

Changing the timestamp of an "anonymous" symlink by file descriptor

The futime* family of functions is implemented with utimensat(fd, NULL, time, 0) while the lutime* ones are implemented with utimensat(AT_FDCWD, path, time, AT_SYMLINK_NOFOLLOW) My best guess from ...
Ericson2314's user avatar
3 votes
1 answer
115 views

Creating a filename for an opened file descriptor

I have a file on the filesystem. I'm opening the file with the open(2) function to get the file descriptor to that file. Now I remove the file. But I still have the file descriptor, so I can read and ...
antekone's user avatar
  • 674
3 votes
3 answers
672 views

When and where are the standard in, out, and error file descriptors first opened in linux?

Where are stdin, stdout, and stderr (the fds) first opened? Is it the kernel that does it? And when and where are the symlinks /dev/std{in,out,err} made? Where is the code that does it? I assume it is ...
Elfen Dew's user avatar
0 votes
1 answer
204 views

When simply `| cat -`, I get file descriptor errors

Here's the working diff command: $ diff -u <(echo 'foo:bar:baz' | tr : "\n") <(echo 'foo:baz' | tr : "\n") --- /dev/fd/11 2023-08-30 13:11:50 +++ /dev/fd/13 2023-08-30 13:...
Scoobie's user avatar
  • 101
1 vote
1 answer
113 views

How to check if stdin have data without IO blocking (docker)?

If I execute echo this | docker run -i alpine cat, I get this. If I execute docker run -i alpine cat, I get blocked terminal, because cat reads stdin, but there is nothing there. I can check opened ...
Andrew15_5's user avatar
0 votes
0 answers
42 views

File descriptor counts differ

There is something fundamental that I miss here, I am sure. On a system I run: cat /proc/sys/fs/file-nr 2240 0 763924 On the same system, if I do : sum=0; for pid in /proc/[0-9]*; do fd=$(ls $...
Eugene's user avatar
  • 101
-1 votes
1 answer
52 views

Portable temporary file descriptors inside `sh -c` [duplicate]

cat <(echo yes) Displays "yes". And running this inside sh -m results in the same thing on Bash 5.2.15. Yet on Bash 4.4.20 it throws an error: sh -c "cat <(echo yes)" sh: -c:...
Zaz's user avatar
  • 2,597
0 votes
2 answers
256 views

Which file descriptor numbers are safe to use in (POSIX) shell scripts?

Chapter 3.6 Redirections of the Bash manual says: Redirections using file descriptors greater than 9 should be used with care, as they may conflict with file descriptors the shell uses internally. ...
finefoot's user avatar
  • 3,102
0 votes
1 answer
185 views

Temporary symlink in shell - "named process substitution" - rename a file without creating a copy/symlink on the disk?

Thunderbird doesn't open files that don't have .eml extension as email files, but instead starts to compose a new message and adds them as attachments. To use thunderbird in scripts I'm looking for a ...
Daniel Krajnik's user avatar
1 vote
2 answers
651 views

Capture and redirect stdin (user input) for runtime of script

I can redirect the stdout/stderr of everything in a script like this: #!/bin/bash exec > stdout_file echo example But now I want the stdin of the whole script to be written into a file. I tried it ...
Nudin's user avatar
  • 111
0 votes
0 answers
393 views

Why is /fd/1 (stdout) a socket?

I'm running a game server as a systemd service, and in the .service file, I see that StandardOutput defaults to journal. Ihsan@IhsanServerVM:/proc/28617/fd$ file 1 1: symbolic link to socket:[510374] ...
ihsan's user avatar
  • 101
0 votes
1 answer
306 views

how to close stdout for program from shell?

I mean not to redirect stdout to /dev/null, but block stdout before starting my program, so for example all of my write(1, "dd", 2); will return -1 as if stdout doesn't exists in my device.
Daniil Rozanov's user avatar
0 votes
1 answer
89 views

bash IO redirection, how du dup() STDERR?

Consider the following example: exec 10>&2 # duplicate STDERR to fd 10 { echo ok; inexistantcommand; } > /tmp/both 2>&1 10>/tmp/err exec 10>&- # close fd 10 I expect /tmp/...
Mévatlavé Kraspek's user avatar
0 votes
0 answers
399 views

Change soft limit of file descriptors on Fedora

I've encountered an issue that require me to increase the max open file descriptors for Chrome. However, I did not have luck and the value seems to stuck at 1024 and I can't increase it. I'm using ...
Alvin Novian's user avatar
0 votes
0 answers
106 views

Redirect output to /dev/fd/x in POSIX script, where /dev/fd/x replaces process substitution

I have a would-be POSIX script that includes filtering the stderr output: exec <cmd> "$@" 2> >(grep -v "blih bluh blah") Redirection does not occur because process ...
Cbhihe's user avatar
  • 2,731
1 vote
1 answer
51 views

Why does zsh descriptor 10 not have same offset as 0/1/2 when it is connected to same tty? Does that matter?

Why does zsh descriptor 10 not have same offset as 0/1/2 when it is connected to same tty? Would it matter if one were to close fd10 and immediately duplicate fd0 to it? On bash the equivalent 255 has ...
codepoet's user avatar
  • 596
0 votes
1 answer
144 views

Why are all of fd0/1/2 opened in read-write mode by bash/zsh?

In my understanding, fd0 is for stdin, so a process would just read from it and never write. Similarly fd1 and fd2 are for stdout/stderr, so a process would just write to it. But it seems like bash/...
codepoet's user avatar
  • 596
0 votes
0 answers
342 views

Write data into read-end of a pipe or vice versa

From pipe manual page A pipe has a read end and a write end. Data written to the write end of a pipe can be read from the read end of the pipe. My understanding is that pipe is a buffer (in memory) ...
joshuako's user avatar
0 votes
1 answer
168 views

How does the Kernel implement synchronisation techniques on file access

I've read that the kernel implements synchronisation mechanisms when accessing files. For example, if we try and write or read to a file in the file system using read() or write() from different ...
Engineer999's user avatar
  • 1,161
0 votes
1 answer
148 views

Pass file descriptor through su -c

Given a file descriptor fd open in c program A, I want to start program B with fd open as U2. On my system (wsl2 ubuntu), execl("/usr/bin/su", "su", suarg1, "U2"); (where ...
user20524567's user avatar
1 vote
2 answers
492 views

Is there a way to force the write command to block until all bytes have been written?

Per the man pages, the write command "writes up to count bytes" and then returns the actual number of bytes written. Thus if I wanted to ensure all bytes were written to the file descriptor, ...
Izzo's user avatar
  • 971
2 votes
1 answer
187 views

Order of fd allocation in process substitution

Inspired by this answer https://security.stackexchange.com/a/166645 I am wondering the reason behind the weird ordering when I run these commands: root@6cb8704148bf:/usr/app# echo <(printf "...
jamylak's user avatar
  • 123
1 vote
0 answers
150 views

Issue with redirecting output to double digit file descriptor

/tmp$ python Python 2.7.6 (default, Nov 13 2018, 12:45:42) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>&...
user138645's user avatar
0 votes
1 answer
211 views

Named file descriptors with Process Substitution

I'm trying to use named file descriptors with Process Substitution. I wrote the following code but it doesn't work: # Open named file descriptors and associate to Process Substitution result exec {...
Dor's user avatar
  • 2,545
0 votes
1 answer
132 views

echo >>regular_file vs echo >>&fd: one closes, other does not

In my observation, echo to regular file echo >>regular_file opens the file, appends to it, and then closes the file. Whereas echo to an open file descriptor echo >>&fd* doesn't close ...
codepoet's user avatar
  • 596
2 votes
1 answer
184 views

trap is ignored when dialog is running with custom BASH_XTRACEFD

I have following script #!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" set -x trap _reboot INT DIALOG_TITLE="This is fancy dialog title" _reboot() { echo ...
Marko Todoric's user avatar
1 vote
3 answers
827 views

Is there an equivalent to /dev/stdout for file descriptors 3-255?

I know that one can often trick command line utilities that expect a file to pipe into stdout out by passing /dev/stdout as the file name. I'm wondering whether it's possible to make a tool pipe to a ...
Cornelius Roemer's user avatar
1 vote
1 answer
602 views

Is 2 pipes more expensive than 1 socketpair?

Suppose I want to launch a co-process and attach its standard input and output to the main process, what we have here are 2 options: call pipe(2) and create 2 pipes, and attach them separately to the ...
DannyNiu's user avatar
  • 620
1 vote
1 answer
260 views

Not understanding the use of EVIOCGRAB for touchscreen devices

I am looking at a userspace library which handles touchscreen events from the Linux kernel. The following line of code, I can't understand what it does. What is the purpose of EVIOCGRAB when passed to ...
Engineer999's user avatar
  • 1,161
2 votes
0 answers
267 views

how to close file descriptor bigger then 9 by dash in shell script

I want launch a shell script in code called system("sh example.sh"), and close all file descriptors like this: for fd in $(ls /proc/$$/fd); do case "$fd" in 0|1|2) ;;...
meilin's user avatar
  • 21
-1 votes
1 answer
433 views

Can the stdout (1) file descriptor be re-used after closing?

I first call close(1) and then later open a file using open() syscall. Is it possible that open() returns 1 because it will use the lowest free file descriptor? I have read that open() uses the lowest ...
zomega's user avatar
  • 972
3 votes
2 answers
2k views

What do the permissions mean in /proc/<pid>/fd/?

I'm looking at the result of running ls -l on /proc/<pid>/fd/: lr-x------ 1 root root 64 Apr 22 23:13 0 -> /dev/null lrwx------ 1 root root 64 Apr 22 23:13 1 -> 'socket:[19700]' lrwx------ ...
Daniel Walker's user avatar
2 votes
0 answers
217 views

FIFO and simple bash parallelization on CentOS

I am having problems adapting a bash script to handle a simple parallel execution from Ubuntu 20.04 to CentOS Linux 8. In the script I spawn multiple "readers" that read a string from a FIFO ...
Sine's user avatar
  • 21
2 votes
2 answers
3k views

meaning of file type c in ls -l command [duplicate]

I am wondering what the type c is in the ls command. I was following the symlinks at /dev/stdin and ended up with /dev/pts/0 $ ls -l /dev/pts/0 crw--w---- 1 blue tty 136, 0 Apr 8 21:50 /dev/pts/0 I ...
The Fool's user avatar
  • 165
2 votes
0 answers
334 views

bash: writing to the file descriptor #3 of an unnamed (anonymous) pipe

I need to call a PHP interpreter, which is in a docker container, from my Linux host system. For some reasons I don't want to install PHP on the host system. Now I'm trying to call PHP in this way: ...
novascriptum's user avatar
3 votes
0 answers
308 views

Bash - Reading from file descriptor twice

I am working with Linux file descriptor at the moment to communicate with an external device via serial port, and I wonder if it is possible for me to duplicate the result returned the device. In ...
MDuc1__6's user avatar
0 votes
0 answers
3k views

kafka + too many open files between Kafka brokers or may between broker and clients

we are facing very major problem with our Apache Kafka servers our Kafka servers are creased because "Too many open files" we have production Kafka cluster with 7 machines , while Kafka ...
yael's user avatar
  • 13.3k
0 votes
1 answer
754 views

What would be the stream for file descriptor 3u?

I know that the stream for file descriptor 2u is stderr. However, I'm not sure what the stream for file descriptor 3u would be and why? Ultimately, what does 3u represent here?
user avatar
0 votes
1 answer
2k views

Writing in the file descriptor of the child process (fd/0)

I'm playing with file descriptors in my CentOS 7 sandbox. In doing so, I noticed an interesting situation. Suppose we've a simple PHP script: $step = 4 * 1024; echo "php started\n"; while (!...
novascriptum's user avatar
0 votes
1 answer
422 views

execlp "sort" with input from pipe stucks, why?

sort is waiting, but what? I tried execlp("head", "head", "-n", "3", NULL); instead sort and it works fine. #include <stdlib.h> #include <sys/wait.h&...
amordo's user avatar
  • 103
1 vote
1 answer
441 views

File descriptor 10 when running a script (Bash/dash, etc.)

When the script runs, a file descriptor 10 appears with the contents of the executable script. For example, the script: #!/bin/sh sleep 600 When viewing the fd of a running script through processes, ...
NewLinux's user avatar
  • 147
2 votes
1 answer
892 views

increasing fs.file-max: what are the others kernel params need adjustments (for running kafka)

For running a kafka service (with jbod disks, where we encountered problems due to too many open files) with an increased LimitNOFILE of 500000, we decided to increase the fs.file-max from 500000 to ...
yael's user avatar
  • 13.3k
1 vote
2 answers
8k views

how to find the number of open files per process

we have kafka service ( as systemctl service ) and we configured in that service number of open files example: [Service] LimitMEMLOCK=infinity LimitNOFILE=1500000 Type=forking User=root Group=kafka ...
yael's user avatar
  • 13.3k

1
2 3 4 5
8