[CentOS] bash job control and signals

Wed Aug 29 20:00:47 UTC 2012
Theo Band <theo.band at greenpeak.com>

I want to suspend a script using a signal but that does not work as I
want. I made an example script:

$ cat script
echo $$

If run this script gkrellm starts up and I can use job control from the
terminal to suspend the script (CTRL-Z) and resume it (fg or bg).
If I suspend I can see that gkrellm freezes (that's why I choose gkrellm
in this example):

$ ./script
[3]+  Stopped                 ./script
$ fg

Next I want to do exactly the same but from another terminal using a signal:

kill -SIGSTOP 23632

[3]+  Stopped                 ./script

So the bash script is indeed suspended, but the gkrellm keeps running. I
can of course signal SIGSTOP to gkrellm and then this gkrellm will
suspend as well. I have however an application that suspends my script
and I cannot change this application. I want all processes that are
children also to become suspended. I tried to add a trap, but that did
not work.

Any idea how to make this work?