Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

For example, how to do this:

$ job1 &
$ p1=$LASTPID
$ job2 &
$ p2=$LASTPID
$ wait $p1 $p2
share|improve this question

2 Answers 2

up vote 7 down vote accepted
job1 &
p1=$!
job2 &
p2=$!
wait
share|improve this answer

If bash is your shell and you might stumble upon the following error, if you try to put all the statements into one line:

$ job1 & p1=$!; job2 & p2=$!; wait
-bash: !: event not found

The ! character invokes bash's history substitution. To get around this you need to add a space between the $! and the ;, like this:

$ job1 & p1=$! ; job2 & p2=$! ; wait
[1] 20198
[2] 20199
...
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.