Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
2answers
34 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....
1
vote
1answer
29 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 ...
0
votes
1answer
38 views

Why is a deleted file still writable in Linux

I'm using Linux for a while and today I found an interesting thing. Saying that I have an infinite task, which keeps writing strings into a file. At some moment, I delete the file, and in several ...
1
vote
1answer
67 views

Redirect script stdin to file in the background

In order to pass my script's stdin to stdin of a command in an alacritty instance it spawns, I'm trying to redirect it to a file in the background (so that the command can start reading it): t="$(...
0
votes
0answers
22 views

What `ulimit` value applies to a `systemd` service?

I have a systemd service installed. It was creating some problems and I am speculating that it might be file descriptor stuff. The file descriptor limit systemd wide is quite high: $ cat /proc/sys/fs/...
1
vote
2answers
34 views

When I start a process on my computer, I see a file descriptor number 6 open, what is that descriptor for/about?

Today I noticed I was getting an error from a tool which verifies its file descriptors on startup. The fact is that I get an extra pts connection: # In one console I start `cat` linux $ cat >/tmp/...
4
votes
3answers
756 views

Does `echo -n | …` send an EOF to the pipe?

Does echo -n | ... send an EOF to the pipe? I.e., echo -n | sth Will sth recieve an EOF on its stdin?
2
votes
1answer
54 views

For a directory file descriptor dfd, can I prevent traversing up as in openat(dfd, “..”, …)?

I have a user $service with a directory /srv/$service/subdir. /srv/$service has a mode of 0700, i.e. it's only accessible by $service. That user can open a directory file descriptor to …/subdir or any ...
1
vote
0answers
21 views

Redirection: what does this redirection chain do--logic and purpose? [duplicate]

recently came across several chained redirections to file descriptors as shown is the snippet below: name=$(dialog --inputbox "Please enter your phone number." 10 30 3>&1 1>&2 ...
0
votes
0answers
26 views

Testing if a file descriptor is valid in really old shells

This is a follow-up question for "Testing if a file descriptor is valid." I am looking for a way to test whether file descriptors are valid that works, including with fds 0, 1, and 2, on ...
1
vote
1answer
66 views

Possible in bash to conditionally redirect output to either stdout or /dev/null?

Use-case: I am writing a script that will accept --simulate which acts as a dry run and only prints the command rather than running it. When running normally (i.e. not with --simulate), the command ...
0
votes
2answers
84 views

What does it mean when a file descriptor is a link to a pipe?

When I look at ls -la /proc/<pid>/fd, I see that stdout is a link to a pipe: lr-x------ 1 admin root 64 Jul 9 21:22 1 -> pipe:[1155] What does it mean? Who is listening to ...
0
votes
1answer
38 views

is parallel write to eventfd is safe?

I have a multi threaded environment so parallel write to eventfd is possible. Is parallel write to eventfd is safe? Is there any official doc that explains this behavior of eventfd.
0
votes
0answers
35 views

Read user input from piped function

I want to use a function's piped content as message to an interactive prompt, still from inside the function. Here is what I tried; myfunc () { local input output output=$(cat /dev/stdin) ...
3
votes
3answers
555 views

Check if a filedescriptor refers to a deleted file (in Bash) [duplicate]

I would like to check if the file that a filedescriptor points to is deleted in Bash (linux). I have read both Testing if a filedescriptor is valid and Testing if a filedescriptor is valid (for input)....
1
vote
1answer
69 views

select would indicate pipe is readable when there's no data in pipe and write end is closed?

I am reading The Linux Programming Interface. From 63.2.3 When Is a File Descriptor Ready?, it says: Correctly using select() and poll() requires an understanding of the conditions under which a ...
0
votes
0answers
14 views

Safety of here document redirecting to file descriptors?

I want to run multiline python scripts by pasting into bash terminal. I discovered here documents and file redirection, as quoted from this answer; exec 3<<'HERE' import sys print("Line Zero!")...
0
votes
0answers
51 views

Location of the system-wide file table and inode table structures in the kernel source

To better understanding of the file management in Linux kernel I want to find out three table declarations in the source: a single process file descriptor table system-wide table of open files inode ...
0
votes
1answer
50 views

File descriptors of executable binary file and shared libraries in /proc/PID/fd?

Do user processes keep a file descriptor for the executable file itself, and for shared libraries? For example, if I look into /proc/PID/fd of bash, I expected to see at least the following fds, ...
1
vote
1answer
70 views

Write multiple lines to file descriptor without here-doc and delete it after reading <&{fd} without blocking

#!/usr/bin/env bash auth() { exec 3<<AUTH $1 $2 AUTH } auth test pwd sh -c 'cat <&3' I want to temporarily store credentials in an auth file/mem of the format user/npass, which ...
0
votes
1answer
84 views

Redirect Cron Stderr and Stdout to A Log File With a Timestamp

I'm trying to get stdout and stderr to make it to my log file for a cron process. Currently, stdout makes it as intended, but stderr does not. My timestamps are creating the issue. If I remove the ...
4
votes
3answers
295 views

How to save stdout to file, stderr to file, stdout+stderr to file and get stdout + stderr to terminal like normal for a shell script

How can I save stdout to one file, stderr to another file, stdout+stderr to a third file and also get stdout + stderr to terminal like normal for a shell script? I found this elsewhere: exec > &...
2
votes
2answers
57 views

How can I simulate an unresponsive file descriptor?

We have an application that writes to a log file. In the prod environment, the log file directory is mapped to a NAS: 192.168.1.10:/storage/app/log 2554360832 11844608 2412762112 1% /usr/local/app/...
0
votes
0answers
20 views

Redirecting and then moving target file [duplicate]

I tested the following on AIX and it works. logfile=log.txt echo "Hello" > "$logfile" exec 1>>"$logfile" mv "$logfile" "${logfile}_new" echo "World" After this script ran the file log....
1
vote
0answers
41 views

custom camera feed on fedora when using zoom.us

zoom work conferences became very popular lately. I saw some of my colleagues (who have macOS) use snap camera in zoom, so I tried looking for a goofy camera I can use as well on linux (fedora 29). I ...
1
vote
4answers
383 views

Reading from stderr in c

This is my c program read from stderr i write #include <uninstd.h> #include <stdio.h> int main(void) { char buff[3]; read(2, buff, sizeof(buff)); printf("%s", buff"); return 0; } My ...
0
votes
0answers
23 views

How can i control shell via stdin descriptor [duplicate]

I found out that launching, for example, sh and then piping command into its stdin descriptor does not affect opened sh anyhow. Why? How can i bypass it? How to reproduce: Launch sh In other ...
0
votes
1answer
41 views

Suppress sftp's info and errors but show progress

I have this sftp -q my_host:my_dir 1>/dev/null 2>&1 <<EOF some_command some_command some_command some_command put foo bar some_command exit EOF This suppresses: banner ...
1
vote
1answer
252 views

How to correctly use strace -e read=fd option?

I'm trying to monitor read activity on a particular file descriptor in a running process. Here is the C++ test bench I'm testing various solutions on: #include <fcntl.h> #include <unistd.h&...
-1
votes
1answer
274 views

What does file descriptor have to do with process table?

I have an interest in Operating Systems. So I am reading the xv6 book to understand Operating Systems. This is my first book on the subject. I read a line I couldn't understand. Internally, the xv6 ...
0
votes
0answers
56 views

Can kernel guarantee that POSIX close frees the descriptor?

Linux developers argue that it's pointless to retry close operation in case of an error, since the kernel "always releases the file descriptor early" (emphasis mine). While in general fildes state ...
0
votes
0answers
75 views

Is it guaranteed freshly opened `/dev/fd/3` always reads from start?

This is a Linux-specific question. The bash script is: echo foo > "a.txt" exec 3<"a.txt" cat /dev/fd/3 cat /dev/fd/3 cat /dev/fd/3 Output: foo foo foo All these cats display the content of /...
4
votes
1answer
65 views

bash: use different input streams for loop condition and body

i have a script with a while loop like this: while IFS= read -r name; do {body} done < names.txt the loop condition needs to read names from a file, but {body} needs to read from stdin; the ...
2
votes
2answers
163 views

Redirect stdout to command-A if success else stderr to command-b. While avoiding using temporary files

I have a command that writes to stdout when it is happy and stderr when it's not. I want to check the exit status of the command and do something with either stdout or stderr. if ! command >/tmp/...
2
votes
2answers
496 views

Startx as non-root user via SSH

I have a remote VM running Ubuntu 1804 and would like to run VNC. I am using x11vnc, which requires an X server to be running. Currently, I'm connected through SSH. The VM has an Nvidia card, and ...
4
votes
0answers
87 views

Bring back a deleted file without copying its content [duplicate]

As long as there is an open file descriptor pointing to a file, I can bring it back with cp like this: # Open for reading exec 3< file # Delete rm file # Bring it back cp /proc/self/fd/3 file ...
2
votes
2answers
58 views

Better method to get a side-value from awk

I have a script whose main purpose is to gather some information and output it in a table. The primary part is an awk script: awk ' { # do some stuff, including calculating dwt ...
3
votes
3answers
290 views

Communication between two file descriptors (clients)

I am following this document I struggle to wrap my head around file descriptors and how I could read data from one, process it and then send to another. As a server I need to be able to accept ...
8
votes
1answer
402 views

Why bash redirection to a file happens in append mode

given this snippet: exec 3>f echo foo >&3 echo bar >&3 cat f # returns foo bar Why is bash appending to f? Am I missing something?
0
votes
1answer
73 views

Cannot cat .pem file inline as -i option to ssh

I am getting this error: Warning: Identity file /dev/fd/63 not accessible: Bad file descriptor. when running this command: ssh -Y 'root@ec2-54-xxx-94-xxx.us-west-2.compute.amazonaws.com' -i <(...
-1
votes
1answer
101 views

Shell fails to find file descriptor file when `cat`ing it [duplicate]

I created a TCP socket and tried to examine its file descriptor. I can list it without a problem: [/proc/24846/fd]$ ls -al 11 lrwx------ 1 danb danb 64 10-Sep-19 22:58 11 -> 'socket:[38186892]' ...
0
votes
4answers
335 views

How to pipe fd 3 to consumer instead of fd1 / fd2

I was hoping to do something like this: echo 'foo' >&3 3| cat Basically, I want to write 'foo' to 3, and then only pipe the data in 3 to cat. But the above doesn't work, I get: bash: 3: ...
0
votes
1answer
608 views

Set-UID Capability Leak Attack

I have a C program to demonstrate the capability leak attack regarding set-uid. // cap_leak.c #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> ...
16
votes
4answers
3k views

Why should fork() have been designed to return a file descriptor?

On his web page about the self-pipe trick, Dan Bernstein explains a race condition with select() and signals, offers a workaround and concludes that Of course, the Right Thing would be to have fork(...
0
votes
1answer
114 views

How to work with file descriptors stored in variables?

For example, if I assign TWO=2 ...the following fails (with date: invalid date '2'): date >> logfile $TWO>&1 Of course, I can always do eval "date >> logfile $TWO>&1" ...
2
votes
1answer
153 views

Understanding anonymous pipe ID

I'm currently debugging a system which has a resource leak. It seems that we have too many pipse open. When I go the my /proc/PROC_ID/fd I see the list of pipes l-wx------ 1 root root 64 Jun 30 12:32 ...
0
votes
0answers
48 views

Separate stdout of an application

I have an application that takes a few command line parameters, then prints some text to the terminal, then starts writing data to a file. It has a parameter I can use to define the file name to write ...
2
votes
2answers
595 views

Flush the pipe/printf buffers externally for already running process with known PID

I am writing a data logging app, all programs are started like: ./program > out.bin The data collector periodically pools the stdout output files and reads the data. The issue is that the IO ...
1
vote
1answer
674 views

How to source inline text

When you are creating tutorials online for people to use in a single terminal sometimes it's nice to source inline code...however none of these worked as I would expect. I would expect foo to be "bar" ...
0
votes
1answer
147 views

Process substitution to script in order to monitor iotop

I am actively trying to get the output of the iotop for monitoring. As you know, the iotop is interactive, meaning that once started, it'll provide live updates on disk usage on the system. I'm ...

1
2 3 4 5
7