Reputation: 143
i need exit status of last background task completed.so that i can judge if it is failed or passed. I do this .
#!bin/sh
task1 &
task2
echo $? # give the exit status of last command
Upvotes: 2
Views: 2813
Reputation: 53
Wait does not return the status of task1. If you need the status you will have to specify the pid of the task1.
Upvotes: 0
Reputation: 362087
You can't get the exit status of the background command unless you call wait
to wait for it to finish. The exit code from wait
is the exit code of the background task, so if you check wait
's exit code that'll be the value you want.
task1 &
task2
wait
echo $?
Upvotes: 3