Linked Questions

54
votes
5answers
12k 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., ...
24
votes
8answers
4k 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?...
28
votes
7answers
34k 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 ...
17
votes
4answers
4k 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 ...
10
votes
5answers
19k 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?
4
votes
5answers
2k 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\...
6
votes
2answers
5k 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 ...
7
votes
3answers
2k 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 ...
13
votes
2answers
2k 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 ...
9
votes
1answer
1k 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.
3
votes
2answers
3k 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 ...
2
votes
2answers
755 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 ...
3
votes
2answers
854 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 ?
2
votes
4answers
301 views

Can a running script identify the logging context?

Let us say I redirect the STDOUT, STDERR of a program to files. ./script.sh 1> output.log 2> error.log Can the running program find this out i.e. know the paths to these files?
5
votes
1answer
664 views

Why doesn't sed exit immediately after writing the output?

I ran sed on a large file, and used the pv utility to see how quickly it's reading input and writing output. Although pv showed that sed read the input and wrote the output within about 5 seconds, sed ...

15 30 50 per page