Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Catch exit code of specific background process

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-30-2013
Xedrox Xedrox is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 5 September 2014, 4:05 PM EDT
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
Catch exit code of specific background process

Hi all, i hava a specific backgroud process. I have de PID of this process. At some time, the process finish his job, is there any way to catch the exit code? I use "echo $?" normally for commands.

Thanks!
Sponsored Links
    #2  
Old Unix and Linux 01-30-2013
neutronscott's Unix or Linux Image
neutronscott neutronscott is offline Forum Advisor  
script kiddie
 
Join Date: Jun 2011
Last Activity: 27 October 2016, 11:56 AM EDT
Location: South Carolina, USA
Posts: 936
Thanks: 30
Thanked 300 Times in 279 Posts
Have a look at wait


Code:
mute@clt:~$ { sleep 30; exit 123; } &
[1] 24619
mute@clt:~$ wait 24619
[1]+  Exit 123                { sleep 30; exit 123; }
mute@clt:~$ echo $?
123

of course, wait blocks...
Sponsored Links
    #3  
Old Unix and Linux 01-30-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 5 December 2016, 4:51 PM EST
Location: Galactic Empire
Posts: 3,529
Thanks: 248
Thanked 1,281 Times in 1,203 Posts
Use wait

Code:
wait <PID>
status=$?

EDIT: too late...
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Catch Zombie Process ckwan AIX 1 11-03-2011 05:36 AM
Background process, return code and pid. RECrerar Shell Programming and Scripting 5 08-13-2011 06:30 AM
catch a particular word from a specific line -perlscript pspriyanka Shell Programming and Scripting 2 06-15-2011 02:03 AM
Return code of background process c19h28O2 Shell Programming and Scripting 3 04-06-2008 12:46 PM
background process return code Vikas Sood Shell Programming and Scripting 5 06-10-2006 10:25 AM



All times are GMT -4. The time now is 04:32 AM.