0

I wrote a simple test program that works fine.

#/bin/bash

run_ajob() {
   # sometime the job is short to send a signal to parent
   if [ "$job" = "short" ]; then  # this is a pseudo code different kinds of job, the elaborate code is much longer
       kill -s SIGUSR1 $parent
   fi
}

# parent process for job control
shortjob=F
export parent=$$
echo $shortjob in parent $parent
trap "{ echo 'got mouse'; shortjob=T; }" SIGUSR1
run_ajob&
sleep 5 # add this line to prevent the parent process from terminate too soon
echo $shortjob

# output from the program
F in parent 22755
got mouse
T

However, this same code pattern, when used in my production pipeline caused the parent process to be killed. Strange enough, initially for several months, the large shell scripts worked fine, but suddenly it started to kill the parent process. Not sure what change cause this unexpected behavior; I made some small modification to the large script somewhere else unrelated. This script is used in a slurm cluster environment. I know IT changed something about the slurm. Spending whole day and night did not get any solution to this simple problem. I must have stuck somewhere that someone can point out.

  • 2
    how does "job" = "short" test true? – thrig Nov 27 '18 at 4:47
  • That's just a pseudo code. I experimented with different amount of sleeps before signaling. I can even make the parent killed (from the child perspective) and still running. Not sure what other factors can affect the behavior of trap. In my real application, the trap is not receiving the signal. – Kemin Zhou Nov 27 '18 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.