Wednesday, July 31st, 2013, 7:00 am
UNIX/Linux: Suspend and Resume Process in Intervals
AVING spent over an hour searching the Web and asking around the Web for a way of automating suspension and continuation (SIGCONT and SIGINT) of process execution in GNU/Linux, I finally found a script from Q. Boiler, which I have modified a bit to make it simpler to use.
Sometimes the scheduler used in GNU/Linux systems is so resources-greedy that it will let a process take up all the CPU/core cycles and in some cases, as in mine, lead to overheat and system shutdown (my ventilation seems to be flawed or maybe to blame is the unusual summer weather here in the UK because this only ever happens in summer). Anyway, having struggled to find a way to nice
a process sufficiently or send the process a universal system signal to help reduce its load on the system, I finally found something which can automate what I have been doing manually (CTRL+Z and fg
), especially when rendering some Blender3D clips for my own use. Here is the simple script to be run:
#!/bin/bash # Based on a script from Q. Boiler (q.boiler@quantprinciple.com) var0=0 LIMIT=20 PROCESSID=$1 SLEEP=30 RUN=10 pid=$PROCESSID while [ "$var0" -lt "$LIMIT" ] do kill -SIGSTOP $pid echo "Suspending $pid" sleep $SLEEP kill -SIGCONT $pid echo "continuing execution $pid" sleep $RUN done echo "killing $pid" kill -SIGINT $pid
The way to use this is to save the above as a script, say script.sh
, give it running permissions, e.g. chmod 755 script.sh
, then call it with the process ID as the argument name, e.g. script.sh 46223
. The intervals for running can be set within the script or with slight modifications be passed as arguments to the script (this is not crucial for my needs). In case someone else runs into the same problem I have decided to document this publicly.