Bash Job Control And Signals

Home » CentOS » Bash Job Control And Signals
CentOS 2 Comments

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

$ cat script
#!/bin/bash echo $$
gkrellm

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
23632
–CTRL-Z

2 thoughts on - Bash Job Control And Signals

  • The magic phrase you’re looking for is “process group”. When you press control-Z a signal is sent to all the process in the process group, but when you send a “kill” it’s only sent to one process.

    So
    % ps -o pgrp $your_process

    That’ll tell you the process group. Then you kill -STOP -pgrp
    (note the negative ID sent to kill)

    That’ll send a signal to all processes in the group

  • Thanks Stephen

    That’s exactly what my application does wrong. I will ask the vendor to change the way they signal the external script. It’s basically only adding a dash before the signal and it works!

LEAVE A COMMENT