wait - return code 127


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users wait - return code 127
# 1  
Old 11-10-2011
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.



Code:
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
Code:
while read line
do 
   script_backgrnd.sh $line &
   pid=$!
   echo $pid > $pid_list
done
< $list

Waiting on Background processes
Code:
while read line
do
    wait $line
done < $pid_list

# 2  
Old 11-11-2011
Yes, that is what the bash man page says, but I observe the following:

Code:
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.
# 3  
Old 11-11-2011
I randomly get return codes, sometimes its 127, sometimes its 0 for the same script thats being called as background process.
# 4  
Old 11-11-2011
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.
# 5  
Old 11-11-2011
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.
# 6  
Old 11-11-2011
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?
# 7  
Old 11-11-2011
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

127.0.0.1 vs 0.0.0.0

Which one should I use in '/etc/hosts'? Please explain in details. Random quotes on the topic: (2 Replies)
Discussion started by: useretail
2 Replies

2. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies

3. Solaris

multitude of packets from 127.0.0.1

I was checking routing table, and noticed that our server has a lot packets from localhost: Routing Table: IPv4 Destination Gateway Flags Ref Use Interface -------------------- -------------------- ----- ----- ------ --------- .. 127.0.0.1 127.0.0.1 ... (1 Reply)
Discussion started by: orange47
1 Replies

4. Solaris

Can't setup gateway other than 127.0.0.1?

I have just installed Solaris 10 X86 today, but I can't use internet at all on it. When I was installing it, it only asked me to create a hostname, without even asking me this computer is "networked" or "non-networked". After I finished installation, I use "netstat -rn" command, and only see... (3 Replies)
Discussion started by: Diamondust
3 Replies

5. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

6. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

7. Shell Programming and Scripting

rc=127 can't fork

I have a script to download a file using wget. It works if I execute it from the command line. But, if I run it in cron, it doesnt work and I am getting the following in the cron log: > CMD: /export/home/username/test > username 23159 c Tue Aug 1 14:40:00 2006 < username 23159 c Tue Aug ... (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

8. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies

9. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies

10. Shell Programming and Scripting

Background processes return 127 sporadically

I have created a shell script that spawns multiple background processes (spawns sqlplus application). I use an array to capture the process id of those background processes. I then loop through the array and issue a 'wait' command to wait on the process id that was captured in the array. I am... (2 Replies)
Discussion started by: max_largo
2 Replies
Login or Register to Ask a Question