If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Staus of Background jobs

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-04, 15:08
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
Staus of Background jobs

In my ksh script, I'm iinvoking two background jobs ...

I want the script to check the status of the jobs and if one of them returns a non-zero error code, it should come out of the wait state and return a non-zero value ...

I have tried using wait but am missing something ..

Thanks in advance for any help ..

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #2 (permalink)  
Old 10-21-04, 17:01
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
Here's one of the solutions that I think should work:
Code:
#!/usr/bin/ksh
# envelope for the background command 1
bk1() {
  command1
  # send SIGUSR1 to ourselves if command1 returns non-zero code
  test $? -ne 0 && kill -USR1 $$
}
bk2 () {
  command2
  test $? -ne 0 && kill -USR1 $$
}
# trap SIGUSR1
trap "print "Abort" && exit -1" USR1
# start background processes
bk1&
PID1=$!
bk2&
PID2=$!
# wait on background processes; 
# if we receive SIGUSR1 the wait will be interrupted
wait $PID1 $PID2
print "wait returned " $?
Reply With Quote
  #3 (permalink)  
Old 10-21-04, 17:08
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
.....................

Last edited by n_i; 10-21-04 at 19:12.
Reply With Quote
  #4 (permalink)  
Old 10-21-04, 17:09
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
.........................

Last edited by n_i; 10-21-04 at 18:27.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On