Trap signal to a process group

Is there a way to capture a signal sent to a process group so that any of the subprocesses does not fall into the signal?

My problem is that I have an application that terminates perfectly on SIGTERM but breaks unevenly on SIGUSR1, and therefore I would like to protect it from SIGUSR1. I was thinking of writing a simple bash script:

#!/bin/bash

runapp &
childspid=$!

trap "kill -TERM $childspid ; exit" USR1

while true ; do
    sleep 10 ;
done

Unfortunately, the killer is cunning and sends SIGUSR1 to the entire process group, not only the leader.

Many thanks,

+5
source share
3 answers

You can set the SIGIGN disposition in any application using a little perl:

perl -e '$SIG{"USR1"} = "IGNORE"; exec(@ARGV)' realprogram realargs...

until the realprogram changes the signals, then it remains safe from them.

, , , fork(), exec() exec().

. bash, (GAH!), , .

:

natsu:~$ grep SigIgn /proc/$$/status
SigIgn: 0000000000384004

:

natsu:~$ trap '' USR1
natsu:~$ grep SigIgn /proc/$$/status
SigIgn: 0000000000384204

: (

natsu:~$ bash
natsu:~$ grep SigIgn /proc/$$/status
SigIgn: 0000000000384004
natsu:~$ kill -USR1 $$
User defined signal 1

perl:

natsu:~$ perl -e '$SIG{"USR1"} = "IGNORE"; exec(@_)' bash
natsu:~$ grep SigIgn /proc/$$/status
SigIgn: 0000000000384204
natsu:~$ kill -USR1 $$
natsu:~$
+3

SIGUSR1, .

0

runapp SIGUSR1 , .

#!/bin/bash
set -m
runapp&
trap "kill $!; exit" USR1
wait
0

All Articles