I am learning how to run multiple processes in parallel
./script1.sh param1 1>/dev/null 2>&1 &
pid1=$!
./script1.sh param2 1>/dev/null 2>&1 &
pid2=$!
I am not sure what is happening here:
1>/dev/null 2>&1
pid1=$!
Redirect standard output (file handle 1) to /dev/null
1>/dev/null
Redirect standard error (file handle 2) to standard output
2>&1
Assign the PID of the most recent background command to variable pid1 (more in bash man page, special parameters)
pid1=$!
The result is that both standard output and standard error are redirected to /dev/null
More examples can be found here: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html
Normally three files are opened to a program: standard input, standard output and standard error. You can read more about standard streams or redirection at wikipedia.
The following part of the script:
./script1.sh param1 1>/dev/null 2>&1 &
pid1=$!
Translated to plain English:
From current directory ./
run a program script1.sh
with parameter param1
and redirect standard output to /dev/null 1>/dev/null
and redirect standard error to standard output 2>&1
and let the program run in the background &
. Assign the PID of the program that was just started in the background to pid1 pid1=$!
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With