When I run a command (
make on a large project) from the shell, I can type CtrlZ to stop the process and return to the shell. Subsequently, I can run
fg to continue the process.
I'm trying to write a shell script to automate this (specifically, to check my CPU temperature every few seconds and stop the process if it gets too hot, since my computer is prone to overheating). My first attempt worked like this (simplified):
# If the CPU temperature is too high...
kill -STOP "$subpid"
# If the CPU temperature has dropped to safe levels...
kill -CONT "$subpid"
Unfortunately, this didn't work; sending
SIGSTOP to the process didn't pause it (as made evident by its continuing to send output to the terminal). I ran
make & at the command line, sent
SIGSTOP, and checked the process status with
ps; it was listed as stopped (and started again when I sent
SIGCONT), but it was still spewing output and driving up my core temperature! Stopping it with CtrlZ never had this problem, but I don't know how to do that in a script.
What makes CtrlZ different from
kill -STOP, and how can I get the behavior of the former in a shell script?