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
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?
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.