wait - return code 127

Hi All,

I am trying to create background processes and then check their status later. But I am getting return codes as 0,127 randomly

On checking the return codes for wait, I found the below. Do I need to treat return code of 127 as successful as well?? as we know the process id passed is correct.

Is terminated different than successful? I am getting the return codes randomly.

0  
Successful completion. 

1-126  
An error occurred. 

127  
A specified pid or job-id has terminated or is unknown by the invoking shell. 

Calling Background processes

while read line
do 
   script_backgrnd.sh $line &
   pid=$!
   echo $pid > $pid_list
done
< $list

Waiting on Background processes

while read line
do
    wait $line
done < $pid_list 

Yes, that is what the bash man page says, but I observe the following:

spot:(sleep 5; exit 127;) &
[1] 22264
spot:wait $!
[1]+  Exit 127                ( sleep 5; exit 127 )
spot:echo $?
127

Note that the process run asynchronously exits with a 127 return code which is passed along, as it should be, by bash. Kshell behaves the same way.

I would treat any non-zero return from wait as a failure.

I randomly get return codes, sometimes its 127, sometimes its 0 for the same script thats being called as background process.

Is the script/programme that is being invoked yours? Meaning do you know for sure that the programme isn't returning 127? Also, is it possible that the script is invoking something else and just letting that return flow back to your driver?

Which shell are you using, and version? I assume bash.

Looks like the wait command is returning code 127 randomly because sometimes the background process is exiting before the wait process is being called.

Now I need to find a way to capture the return status of the background process. Any Ideas how to do that effectively.

I just set up a test in both shells to invoke multiple processes asynchronously and not to invoke wait until after both had finished. These processes are only finishing 5 seconds ahead of the wait, and I'm not able to force either shell to return 127 from wait.

Maybe an old version with a bug, or a time limit that the shell holds the exit code for -- how much ahead of the wait are your processes finishing?

Hi,

How can we identify the below:

a) Maybe an old version with a bug
b) time limit that the shell holds the exit code

-- how much ahead of the wait are your processes finishing?
It might be in fraction of secs. its a simple loop

Thanks

I don't think the issue is being caused by the asynch command finishing before the wait is issued, espeically if its within a second or two.

If you are using Kshell or bash, run the command bash --version or ksh --version to determine the version. If it isn't the most current, upgrade.

If your scripts are simple, you might want to post them -- might be something in the scripts that is causing the issue too. Hard to say without seeing them.