Wait functionality in Solaris


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wait functionality in Solaris
# 1  
Old 06-02-2013
Wait functionality in Solaris

hi all ,

If pid is not an active process ID, the wait utility will return immediately and the return code will be 0.

i just came across this which means that wait will returm 0 even though the script has failed Smilie so can anyone tell me what is the exact way to get the return status from wait command in bash script ?
# 2  
Old 06-02-2013
If a process no more exists as either active or zombie, its exit status is not recorded anywhere so is unknown. You need to use some other custom mechanism to store its status.
# 3  
Old 06-02-2013
Quote:
Originally Posted by Rahul619
hi all ,

If pid is not an active process ID, the wait utility will return immediately and the return code will be 0.

i just came across this which means that wait will returm 0 even though the script has failed Smilie so can anyone tell me what is the exact way to get the return status from wait command in bash script ?
Not exactly. If I run the bash script (from a file named nonzero):
Code:
#!/bin/bash
(sleep 5;exit 2)&
pid=$!
(sleep 10;exit 1)
echo "return code from synchronous child $?"
wait $pid
echo "return code from asynchronous child that exited earlier: $?"
(sleep 5;exit 2)&
pid=$!
(sleep 10;exit 1)&
wait	# wait for all children to terminate
echo "wait with no pids returned $?"
wait $pid
echo "return code from asynchronous child that has already been reaped: $?"

I get the output:
Code:
return code from synchronous child 1
return code from asynchronous child that exited earlier: 2
wait with no pids returned 0
nonzero: line 13: wait: pid 78859 is not a child of this shell
return code from asynchronous child that has already been reaped: 127

The second line of the above output shows that I do get the exit code from a child that died before I called wait as long as its exit status hadn't already been reaped. The line in blue was a diagnostic written by the shell, not directly produced by the script. The final 127 exit status is an indication that you tried to wait for a child that was not your child or that you had already collected its exit status. You will only get a zero exit status if the child whose status wait collected exited with a zero exit status. (Note that if you kill a process and it is catching the signal you sent; it may still exit with a zero exit status.)
These 2 Users Gave Thanks to Don Cragun For This Post:
# 4  
Old 06-02-2013
thanks a lot 4 dis piece of explanation Smilie !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Zip -r Functionality

Hi , I've written the following code to zip the big file $dir_temp ="/home/etc/hst zip -r $dir_temp/file_nm.zip $dir_temp/file_nm The zip file has been created . When I try to UNZIP the file with the following command unzip file_nm.zip The file got unzipped but created in the... (3 Replies)
Discussion started by: smile689
3 Replies

2. UNIX for Dummies Questions & Answers

Command Functionality

Hi everyone, today i need that someone help to understand this particular line of command. So you can explain to me step by step, it will be great. ---------- Post updated at 11:53 AM ---------- Previous update was at 11:51 AM ---------- (9 Replies)
Discussion started by: Newer
9 Replies

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

4. Shell Programming and Scripting

Shell script runs fine in Solaris, in Linux hangs at wait command

HI, I have a strange problem. A shell script that runs fine on solaris. when i ported to linux, it started hanging. here is the core of the script CFG_FILE=tab25.cfg sort -t "!" -k 2 ${CFG_FILE} | egrep -v "^#|^$" | while IFS="!" read a b c do #echo "jobs output" #jobs #echo "jobs... (13 Replies)
Discussion started by: aksaravanan
13 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

using functionality in another ksh

i have a function defined in one ksh i want to use the same functionality in another ksh i am using . ../<ksh name> but it is not picking that functionality what i have to do for the same (2 Replies)
Discussion started by: trichyselva
2 Replies

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

8. Shell Programming and Scripting

Restartibility Functionality....

Hello, I am trying to write a script that has a option of restarting the script from where it failed. I have to write a script called Batch.sh. This script has to run quite a few sql files as shown below: logcmd.sh -f test1.sql logcmd.sh -f test2.sql logcmd.sh -f test3.sql logcmd.sh -f... (4 Replies)
Discussion started by: rkumar28
4 Replies

9. Shell Programming and Scripting

Sed functionality

I have a few xml files and I want to input say 5 parameters within each file. is it possible to do so with sed? <parameter>A</parameter> <parameter>B</parameter> .... .... And so on. These parameters are meant to go in just inside: <?xml... (2 Replies)
Discussion started by: collern2
2 Replies

10. UNIX for Dummies Questions & Answers

default time in Solaris 8 for time-wait

Ok, heres the situation. We use Solaris 8 and sometimes users who are logged into our system restart their pc's without shutting down the application that attached to our unix backend. I netstat and I get time-waits for the users. My question is how long before the time-wait ends and the user... (1 Reply)
Discussion started by: eloquent99
1 Replies
Login or Register to Ask a Question