6
votes
3answers
1k views

reliable return code of background process

Let's assume the following piece of bash code: foo > logfile 2>&1 & foo_pid=$! while ps -p$foo_pid do ping -c 1 localhost done wait $foo_pid if [[ $? == 0 ]] then echo "foo ...
2
votes
1answer
488 views

How to wait for a subprocess used for I/O redirection?

Consider the following snippet of Bash script: exec 3> >(sleep 1; echo "$BASHPID: here") do-something-interesting exec 3>&- wait $! echo "$BASHPID: there" When executed, it produces: ...
0
votes
1answer
95 views

why there is random behaviuor for a background job?

going through advanced bash scripting guide example 3.3 running a loop in background, i found this : #!/bin/bash # background-loop.sh for i in 1 2 3 4 5 6 7 8 9 10 # First loop. do echo -n "$i " done ...
23
votes
4answers
4k views

How to do nothing forever in an elegant way?

I have a program which produces useful information on stdout but also reads from stdin. I want to redirect its standard output to a file without providing anything on standard input. So far, so good: ...
2
votes
2answers
1k views

Process not working when executed in background inside shell script

I have an application that runs fine, with and without '&' when run directly from the terminal. However, if I try to execute it from a shell script, it works only if the trailing '&' is ...