Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
373 views

Why changing tty settings on one file descriptor affects another?

ECHO setting is enabled on stdin and stdout by default. But why if we disable ECHO on stdin, it is also disabled on stdout? They have two separate descriptors - 0 and 1, so why they are changed ...
2
votes
2answers
403 views

Max out file descriptors

I wish to write a script that will use up all of the available file descriptors on my Linux machine. I am unsure how exactly to do this, or if it is even possible? But I wish to use this script for a '...
1
vote
1answer
375 views

How does GnuPG outputs to console while stdout and stderr are both redirected to /dev/null

Example : bash$ gpg --batch --edit-key alice quit >/dev/null 2>&1 Secret key is available. pub 2048R/9F07612A created: 2017-06-20 expires: never usage: SCEA ...
3
votes
1answer
55 views

Why does moving forward switch the file system here?

If I navigate to a new, empty directory ~$ cd "`mktemp -d`" and mount a file system there /tmp/tmp.4MlNzMERSw$ sudo mount /dev/sda5 . and then try to list the files there, I don't see the files on ...
3
votes
2answers
326 views

Difference between file and file descriptor linked to a file

I have a file which contains four lines: $ cat file First line Second line Third line Fourth line $ When I read this file four times, then I always read the first line which is an expected result: ...
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 ...
2
votes
1answer
1k views

What are file descriptors other than 0, 1 and 2

I am trying to understand the logs of sysdig. It mentions there file descriptors other than 0 (standard input), 1 (standard output), 2 (standard error); file descriptors such as 3, 6, 7, -2 are listed....
0
votes
0answers
1k views

Writting to a Tun/Tap interface

Recently I've been using a tun interface to redirect the Internet traffic through my methods. To do so, I followed this tutorial. My idea is to have a program which receives the IP packets that go to ...
3
votes
1answer
123 views

File descriptor duplication behaviour

I have this file: 1 2 3 4 When I run paste in this manner paste - - <file this results 1 2 3 4 so far so good, standard input(redirected from file) is passed twice to paste ...
0
votes
1answer
277 views

create a Virtual server in virtualmin: mailbox failed, Bad File Descriptor

I'm trying to create a Virtual server in virtualmin and everytime i click in create it displays an error : Creating mailbox for administration user .. .. mailbox failed : Failed to write to /home/...
9
votes
1answer
25k 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 ...
1
vote
1answer
152 views

Is there a way to send a string to the STDIN of an existing PID in AIX?

To give you some context, there's a ksh script running in AIX that contained a rm file.txt instruction - the problem is that the file, being owned by a shared group but by other user, made the script'...
0
votes
1answer
213 views

Syntax confusion about closing file descriptors

I've found mostly confusing the syntax about closing file descriptors. Taking as example: n>&-, i'm closing a file descriptor called n, i'm right ? But i knew that if i want redirect something ...
1
vote
1answer
205 views

Byte Offsets for pipe/FIFO

Why are byte offsets for a pipe/FIFO maintained in the inode rather than the file table, like for regular files? I read this line at page 113 of The Design of The Unix Operating System (1986) by ...
13
votes
2answers
2k views

Why doesn't SSH -t wait for background processes?

Why is it that ssh -t doesn't wait for background jobs to finish? Example: ssh user@example 'sleep 2 &' This works as expected, since ssh returns after 2 seconds, whereas ssh user@example -t '...
1
vote
0answers
412 views

Read from an arbitrary fd of a running process

I have two processes A and B, communicating over a pipe. I would like to be able to read from that pipe, using lsof I can easily find the right fd, unfortunately tail -f /proc/$pid/fd/$fd doesn't seem ...
1
vote
1answer
370 views

How can I read the descriptor for the “Characteristic User Description”?

I am trying to get my Linux machine to communicate with several micro-controllers that have BLE chips. I am attempting to do this using the attributes that already come with the micro-controllers. The ...
1
vote
0answers
61 views

pv working with existing PID doesn't work with -s option

I would like to both use -d and -s option while calling pv. I tried as below: $ cat -n /tmp/x.py 1 import time 2 import threading 3 import sys 4 5 def w(): 6 ...
2
votes
1answer
1k views

How to read a webcam that is already used by a background capture?

A ffmpeg webcam capture is running in the background. ffmpeg -f video4linux2 -s vga -i /dev/video0 capture.mp4 (1) I am therefore unable to read it with ffplay since the device /dev/video0 is ...
1
vote
0answers
666 views

How to fork a ffmpeg stream in order to read it with ffplay?

Say I create an encrypted webcam capture ffmpeg -f alsa -ac 2 -i plughw:0,0 \ -f video4linux2 -s vga -i /dev/video0 \ -f ogg >(openssl enc -k $PASSWORD -aes-256-cbc -out webcam.aes-256-cbc How ...
6
votes
2answers
395 views

dash: Pipe STDIN to multiple commands and their output to STDOUT in defined order

At first I thought this answer was the solution, but now I think I need a temporary file as buffer. This works unreliably: #!/bin/sh echo 'OK' | { { tee /dev/fd/3 | head --bytes=1 >&...
0
votes
3answers
2k views

Writing and reading from file descriptor 3 and /proc

When I run the following command: exec 3<<< "TEST" I can see the following appear in /proc (note last line regarding FD3 reading deleted): # ls -al /proc/$$/fd total 0 dr-x------ 2 root ...
5
votes
1answer
1k views

Opening named pipe blocks forever, if pipe is deleted without being connected

Try the following shell commands: mkfifo /tmp/test.pipe ls -1 /tmp > /tmp/test.pipe & rm /tmp/test.pipe mkfifo /tmp/test.pipe cat /tmp/test.pipe & jobs The ls command is just an ...
0
votes
1answer
332 views

Does opening a regular file by `open()` in a C program create a file `/proc/$pid/fd/$number`?

In Linux, I write a C program, which calls open() to open a regular file and return a file descriptor. When I run the executable compiled from the C program, is it correct that its process creates ...
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 ...
14
votes
3answers
2k views

In the code “{ exec >/dev/null; } >/dev/null” what is happening under the hood?

When you redirect a command list that contains an exec redirection, the exec >/dev/null doesn't seem to still be applied afterwards, such as with: { exec >/dev/null; } >/dev/null; echo "Hi" "...
3
votes
2answers
1k views

Can I duplicate an input file descriptor and use it for writing data?

The below command makes a copy of the input file descriptor and use the duplicate file descriptor for writing data from the echo command on to the terminal. sh-4.2$ exec 6<&0 sh-4.2$ echo "...
2
votes
1answer
258 views

Moving file descriptors in zsh

The construction ls 3>&2 2>&1 1>&3- in zsh does not behave in a manner consistent with ksh/bash or with more limited shells like dash that don't support moving file descriptor at ...
2
votes
1answer
133 views

Why doesn't /proc/self/fd/0 have a writable bit in serial session before a shell is started?

I came across a program which uses a very old version of linenoise library. All write() are done to STDIN_FILENO, like this: write(STDIN_FILENO,prompt,plen) write fails with -1 and errno set to ...
2
votes
1answer
617 views

What is the maximum support for file descriptors based on my CPU

We are using an Amazon EC2 instance running Ubuntu 14.04 and we are stuck with a couple questions. What is the maximum number of open files I can have based on the CPU configuration that we are ...
0
votes
2answers
2k views

Redirection using file descriptors - specific example [duplicate]

I am reading this documentation which gives the following examples about redirection and file descriptors. ls > dirlist 2>&1 will direct both standard output and standard error to the ...
3
votes
1answer
772 views

Is it safe to use fd 3?

There are several questions that use it to do things like multiple output pipes without using process substitution: Is there a way to pipe the output of one program into two other programs? Swapping ...
6
votes
1answer
659 views

Why can't I do ls -a 1>&-?

Why can't we just close stdout for a process? I was trying out redirection commands. The following works: ls -a 0>&- ls -a 2>&- which means close stdin and stderr for the process ls -...
2
votes
3answers
268 views

How does the shell/init create the stdio streams?

I am reading through the source of MIT's xv6 OS. This snippet comes at the beginning of sh.c: // Ensure that three file descriptors are open. while((fd = open("console", O_RDWR)) >= 0){ if(fd &...
2
votes
1answer
128 views

Unexpected behavior of file descriptor and/or I/O streams after running sqlcmd with -i option (read sql from file) in ksh creates infinite loop

Is there a way to use sqlcmd with -i input_file option without creating an infinite loop in my ksh script? The code reads lines from $file and parses it line-by-line to extract data and process other ...
4
votes
0answers
405 views

Find number of duplicate file descriptors on Linux

Given a file descriptor, is there a way in Linux to find out how many other file descriptors refer to the same file description (i.e. how often dup was called, not how often open was called)? I do ...
2
votes
2answers
799 views

Free space not reclaimed after truncating the fd

I have an old log that stays in (deleted) state, and after applying > /proc/'pid'/fd/4 the space is not reclaimed. In fact, the size of file is zeroed, but the space is still used ? Have I ...
3
votes
1answer
280 views

Repeated creation of file descriptor pointing to same file, bash

If I create a file descriptor in bash and point it at a file and put some data into it: exec 5>>file for i in {1..10000}; do echo "$i" >&5 done File descriptor 5 holds open "file" ...
25
votes
1answer
1k views

What is the bash '<(file contents)' syntax called?

This answer on Security StackExchange uses an interesting bash syntax to generate a file in-line: openssl req -new -x509 -nodes -newkey ec:<(openssl ecparam -name secp384r1) -keyout cert.key -out ...
1
vote
2answers
233 views

Why does tcsh consistently have multiple fd's pointing to /dev/tty

This is on Ubuntu 16.04, with bash 4.3.42 and tcsh 6.19 If a open a virtual console not being used by X and run bash, I see stdin, stdout, stderr and a dedicated file descriptor for the tty (...
1
vote
1answer
628 views

where does go data written to file descriptor that was never opened

I have output captured by following command: $ strace -f -e trace=process,socketpair,open,close,dup,dup2,read,write -o rsync.log rsync -avcz --progress src/ dst/ it is a bit long so I've uploaded it ...
17
votes
1answer
3k views

How to terminate a TCP connection established by bash itself?

I have used exec 3<>/dev/tcp/192.168.0.101/6435 to establish a TCP connection with 192.168.0.101:6435. And I have received as well as sent a few messages with the pipe command. Now, I want to ...
0
votes
1answer
1k views

How to manipulate a file descriptor in another process? [duplicate]

Is there any way to manipulate (read, write, etc..) a file descriptor for any app which can be found in the path /proc/{pid}/fd? Especially for sockets. $ ll /proc/4229/fd total 0 lrwx------. 1 ...
1
vote
0answers
23 views

Redirect all output, including input prompts [duplicate]

I know that doing command &> /dev/null suppresses all output file descriptors. But I notice that it does not work for commands that request input from the user, most notably ssh: > ssh ...
4
votes
1answer
956 views

Executing commands in an elevated bash process by writing to the standard input of its parent script process

I have a simple bash script bash.sh that starts another bash instance using pkexec. #!/bin/bash bash -c 'pkexec bash' When executed this shows a prompt for the user to enter their password. The main ...
3
votes
2answers
124 views

Mark descriptor as terminal for the -t test

One can test if a descriptor is connected to terminal with -t test. if [ ! -t 0 ]; then echo "Stdin is not from terminal" fi Having a descriptor X, pointing to a file or to a process (with >(cmd)...
4
votes
2answers
4k views

How “Max open files” soft and hard limit are set for specific process?

I used the cat /proc/<pid>/limits command to check the Max open file hard and soft limit, but I want to know how this value will be set and can it be increased or decreased? Is this value is ...
3
votes
1answer
1k views

mkfifo pipes, file descriptors and ImageMagick (convert)

I'm in trouble using named pipes (i.e. created with mkfifo) and file descriptors to redirect outputs and grab inputs to/from them within ImageMagick (convert). Basically, with the following bash code ...
2
votes
0answers
234 views

How unmounting closes file descriptors?

Checking currently open files on my /Volumes/UNTITLED gives me 2 entries: $ sudo lsof /Volumes/UNTITLED/ COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mds 62 root 8r DIR 1,6 ...
0
votes
1answer
1k views

How to handle broken link after file deletion.in /proc/<pid>/fd directory?

A process is creating huge number of log files and also deleting it. Many of those deleted files are having broken links in the /proc/pid/fd directory. Do these file handles need to be closed by ...