Linked Questions
18 questions linked to/from Portability of file descriptor links
79
votes
6
answers
26k
views
How portable are /dev/stdin, /dev/stdout and /dev/stderr?
Occasionally I need to specify a "path-equivalent" of one of the standard IO streams (stdin, stdout, stderr). Since 99% of the time I work with Linux, I just prepend /dev/ to get /dev/stdin, etc., ...
60
votes
8
answers
73k
views
How to keep Bash running after command execution?
I would like to run something like this:
bash -c "some_program with its arguments"
but to have an interactive bash keep running after some_program ends.
I'm sure -c is not a good way as man bash ...
32
votes
11
answers
12k
views
How do I source another process's environment variables?
If I examine /proc/1/environ I can see a null-byte-delimited string of process 1's environment variables. I'd like to bring these variables into my current environment. Is there an easy way to do this?...
16
votes
7
answers
34k
views
Close all file descriptors in bash
Is there a way to close all the open file descriptors, without having an explicit list of them beforehand?
18
votes
4
answers
6k
views
How can the standard input of one program be passed as an arg to another?
Let's say a program exists, which takes two arguments; input file and output file.
What if I don't wish to save this output file to disk, but rather pass it straight to stdin of another program. Is ...
5
votes
5
answers
5k
views
Reading from file descriptor fails
This question is about reading and writing on a file descriptor. See the following example:
#!/bin/sh
file='somefile'
# open fd 3 rw
exec 3<> "$file"
# write something to fd 3
printf "%s\n%s\...
7
votes
2
answers
19k
views
What's the difference between ">&1" and ">/proc/self/fd/1" redirection?
I'm working on some script that being run by rc.local at startup, and I noticed that output redirection works quite strange.
If I write something like echo "foo" >&1, it ends up in syslog, and ...
17
votes
1
answer
3k
views
Does Posix require any devices?
Does Posix require any devices? For example, /dev/urandom, /dev/zero or /dev/null?
I suspect not because of non-*nix OSes, but wanted to ask for completeness.
10
votes
3
answers
4k
views
`/proc/$PID/cwd` : is there a POSIX equivalent?
Linux has a /proc directory and file‑system, which as far as I can tell, is not part of POSIX. In each /proc/$PID subdirectories, is a symbolic link, cwd, pointing to the actual working directory of ...
20
votes
2
answers
4k
views
Unix systems without /dev/stdin, /dev/stdout, and /dev/stderr? [duplicate]
An answer I gave to a question, and the comments to it, had me read the POSIX Conformance section of the Base Definitions to figure out whether /dev/stdin, /dev/stdout and /dev/stderr were actually ...
4
votes
1
answer
14k
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....
5
votes
2
answers
3k
views
Grab standard input/ouput of a running process under FreeBSD/macOS
Under Linux I often use /proc/<pid>/fd/[0,1,2] to access std[in,out,err] of any running process.
Is there a way to achieve the same result under FreeBSD and/or macOS ?
4
votes
2
answers
5k
views
Pass a command to ROOT from a shell script and having it stay open
I am writing a bash script to perform some analysis using the program ROOT. I want to run some initial command to load the result of the analysis, then continue using ROOT interactively.
The analysis ...
3
votes
2
answers
3k
views
Is it safe to use /dev/stdin if the program doesn't read from standard input but only from files?
I want to pipe the output of a program A in a program B. The program B doesn't support reading from stdin, only from files.
Can I simply do A | B /dev/stdin ?
In fact it seems it works, but I want ...
2
votes
2
answers
1k
views
Linux memory usage?
We have 1TB of memory on a server which hosts an SAP application.
When the app is running the memory usage shown in top is around 700GB. When the app is stopped the memory usage shown in top comes ...