pstop and prun
Many people know how to kill a process, but less people know that you can suspend a running process in to resume the execution later.
The test case
I wrote a small script to demonstrate both commands.
#!/usr/bin/perl
while () {
$zeit=time();
print "... $zeit \n";
sleep(2);
}
It just prints the current time every 2 seconds.
jmoekamp@hivemind:~$ ./stopstart.pl
... 1297973807
... 1297973809
... 1297973811
... 1297973813
... 1297973815
... 1297973817
... 1297973819
... 1297973821
... 1297973823
... 1297973825
... 1297973827
... 1297973858
... 1297973860
... 1297973862
... 1297973864
... 1297973866
... 1297973868
... 1297973870
^C
jmoekamp@hivemind:~$
You may have recognized that there is a 31 second gap between 1297973827
and 1297973858
for script that should print out the timestamps continiously every two seconds.
What i did in a second shell?
What happened here? At 1297973827</a> i ran the following command:
jmoekamp@hivemind:~# pstop 10103
jmoekamp@hivemind:~#
When you look at the process flags, you will see that the process has been stopped:
jmoekamp@hivemind:~# pflags 10103
10103: /usr/bin/perl ./stopstart.pl
data model = _ILP32 flags = MSACCT|MSFORK
/1: flags = STOPPED|ISTOP|ASLEEP nanosleep(0x8047a00,0x8047a08)
why = PR_REQUESTED
A moment before that i found out the process id via
jmoekamp@hivemind:~# ps -ef | grep "stopstart.pl" | grep -v "grep"
jmoekamp 10103 9998 0 21:16:48 pts/2 0:00 /usr/bin/perl ./stopstart.pl
Then i just waited for half a minute and resumed execution with
jmoekamp@hivemind:~# prun 10103
jmoekamp@hivemind:~#
So the perl scripted resumed to print the timestamps at 1297973858
. When you check the pflags again you will see, that the the STOPPED and ISTOP flags went away:
jmoekamp@hivemind:~# pflags 10103
10103: /usr/bin/perl ./stopstart.pl
data model = _ILP32 flags = MSACCT|MSFORK
/1: flags = ASLEEP nanosleep(0x8047a00,0x8047a08)
jmoekamp@hivemind:~#