killing processes
Bill Campbell
linux-sxs at celestial.com
Wed Dec 3 08:40:31 PST 2008
On Tue, Dec 02, 2008, Lonni J Friedman wrote:
>On Tue, Dec 2, 2008 at 6:41 AM, Machiel Richards
><MachielR at agilitytech.co.za> wrote:
>> Hi all
>>
>> I hope someone can assist......
>>
>> We have a cron that runs regularly....however one of the
>> child processes produced by the cron keeps on running even after the cron
>> has completed...
>>
>> This uses up a lot of resources and we have not been able to
>> kill it, not even by using kill -9.
>>
>> This is on a production system and we cannot afford to
>> reboot the server.
>>
>> Can anybody perhaps tell us how to kill these type of
>> processes?
>
>You can't. If kill -9 doesn't work, then the process is either a
>zombie, or blocked on IO of some kind.
A fairly frequent cause of this type of behaviour is a process
that spawns children, then doesn't ``wait'' for the child
processes to terminate. I have run into this with a python TK
script I have that monitors mail folders somewhat like xbiff,
where clicking on a folder's mailbox spawns an ``xterm -e mutt''
command to read that folder. It took me a few tries catching
signals and waiting to get it do clean things up properly.
It's generally a Good Idea(tm) when running cron jobs that may
take a while to create lock files which may be checked by new
jobs to determine if the previous run is complete. The shlock
script from the inn nntp server, perl's LockFile::Simple, and
similar tools can make this fairly simple, creating a lock file
with the pid of the calling process that can then be used to
check the status of that process.
Another way to handle this is to have the cron script create its
own pid file which can be done in a shell script with a few
lines of code:
#!/bin/sh
progname=`basename $0`
pidfile="/var/run/$progname.pid"
# test for running program
[ -s $pidfile ] && {
kill -0 `cat $pidfile` 2>/dev/null && {
echo "$progname still running" 2>&1
exit 1
}
}
echo $$ > $pidfile
### do stuff here
rm -f $pidfile
exit 0
Bill
--
INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186
If you think health care is expensive now, wait until you see what it coses
when it's free -- P.J. O'Rourke
More information about the Linux-users
mailing list