Doozer has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys,

I was after some input on the benefits/risks/problems when using the 'kill' function in linux to pause and resume a perl script.

"kill -STOP (PID)" will pause any running process until the command "kill -CONT (PID)" is given.

The reason this may be useful for me is that I have a perl script that starts 4 other scripts and puts them in to the background. The scripts run for 72 hours (They all work together to run a 'load test' on a router) before finishing.

I need to have a process whereby all of the scripts are paused when a problem is detected with the router such as ADSL line drops or complete failure. I have built pause functions in to scripts before but it can be time consuming to work out the logic and put it in to all 4 scripts, so using the system to just pause the running scripts would be much easier and quicker.

I would guess it depends on what the scripts do as to how good or bad this method of pausing could be but I would appreciate your thoughts

  • Comment on Pause and resume perl script with system kill

Replies are listed 'Best First'.
Re: Pause and resume perl script with system kill
by kcott (Chancellor) on Nov 01, 2013 at 12:27 UTC

    G'day Doozer,

    You may be interested in this recent thread: Scheduling script with pauses

    Also, you may be aware of this, but (in Perl) kill SIGNAL sends the signal to the process and kill -SIGNAL sends the signal to the process group. See kill for details.

    -- Ken

Re: Pause and resume perl script with system kill
by sundialsvc4 (Abbot) on Nov 01, 2013 at 14:51 UTC

    Well then, tell us more about what these scripts do.   Do they simply generate a flood of output in hopes of making the poor router cry “uncle?”   If that is the case, and they are not grabbing any sort of shared-resource in the doing of it, then a simple stop / continue might well be just what the doctor ordered:   stopping them “in their tracks” presumably won’t hurt them a bit, and won’t disrupt the test.   (True??)   But ... you say that the scripts work “together,” though, and that does raise an eyebrow.   In what way do you mean, “together?”   Is the timing / cooperation between them:   non-existent (N/A), loosy-goosey, or tight?   Does “whatever causes the test to be paused” also call for some kind of “recovery mode” about which they will need to be informed?   Or do they really not care whether they are at any particular instant asleep or awake?