Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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 " $?

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    .....................
    Last edited by n_i; 10-21-04 at 20:12.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    .........................
    Last edited by n_i; 10-21-04 at 19:27.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •