The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to include RETURN KEY with Background process "&" in Shell Script racbern Shell Programming and Scripting 1 03-11-2008 07:30 AM
getting the return code of forked child process (ftp) KittyJ High Level Programming 7 08-19-2007 04:44 AM
return code of a process filedeliver High Level Programming 1 04-19-2007 02:42 AM
return code of a process filedeliver UNIX for Advanced & Expert Users 1 04-18-2007 04:27 PM
background process return code Vikas Sood Shell Programming and Scripting 5 06-10-2006 10:25 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-06-2008
c19h28O2 c19h28O2 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 34
Return code of background process

Hi,

I have a process that I run in the background that looks like this


Code:

${BASEDIR}/ksh/sqler.ksh   ${compnames003[$i]} &

and I would like to get the return code of the sqler.ksh script.

so my code is like this


Code:

${BASEDIR}/ksh/sqler.ksh   ${compnames003[$i]} &

retcode=$?

but this always returns 0 becuase the last statment it run was the & so is there a way to get the return code of the sqler script rather than the return code of the background process.

If I remove the background processing it works..

so


Code:

${BASEDIR}/ksh/sqler.ksh   ${compnames003[$i]}

retcode=$?

works but its not running in the background

Thanks
  #2 (permalink)  
Old 04-06-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The return code can only be reaped when the process finishes. Have a look at the wait command. (You will want to wait on that specific process; you get its process ID in $! when you have just started it.)
  #3 (permalink)  
Old 04-06-2008
c19h28O2 c19h28O2 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 34
Hey era,

I was using wait but without the pid, I just literally had "wait" directly underneath.

but now I've changed it to waid for the pid and its now returning the failure code!

Out of interest is the reason it only returns 0 because it doesn't know what process your referring to if you just use wait witout the pid?

Thanks for the help.
  #4 (permalink)  
Old 04-06-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652

Code:
bash$ help wait
wait: wait [n]
    Wait for the specified process and report its termination status.  If
    N is not given, all currently active child processes are waited for,
    and the return code is zero.  N may be a process ID or a job
    specification; if a job spec is given, all processes in the job's
    pipeline are waited for.

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0