Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Background process return code 1

Status
Not open for further replies.

johndrake

Technical User
Jul 25, 2002
97
Hi,

Is their any way to get the return code of a background
process? What I would like to do is to somehow the return
code of a background process after it has finished by
doing echo $?.

Thanks!


-Joe
 
(
my_process
print $?
) &
Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
bg_job&
pid=$!
wait $pid
if [ $pid -eq {whatever value you expected} ]
then
echo "success"
else
echo "bg_job return code is: $?"
fi

WAIT EXIT STATUS
If one or more operands were specified, all of them have
terminated or were not known by the invoking shell, and the
status of the last operand specified is known, then the exit
status of wait will be the exit status information of the
command indicated by the last operand specified. If the
process terminated abnormally due to the receipt of a sig-
nal, the exit status will be greater than 128 and will be
distinct from the exit status generated by other signals,
but the exact value is unspecified. (See the kill -l
option.) Otherwise, the wait utility will exit with one of
the following values:

0 The wait utility was invoked with no operands and
all process IDs known by the invoking shell have
terminated.

1-126
The wait utility detected an error.

127 The command identified by the last pid operand
specified is unknown.
 
Should be noted that art15t's method is the classically correct way of doing things, as opposed to my quick and dirty hack :) Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Thanks Mike!


...and you can also use "set -m" if you just want to know the return code but don't want to do any further processing

ART
 
Hi, in script art15t you have to check (after wait) the value $? instead $pid
Boris
 
Well spotted Boria! yes that should have been if [ $?.....


ART
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top