killing processes

Bill Campbell linux-sxs at celestial.com
Thu Dec 4 09:12:24 PST 2008


On Thu, Dec 04, 2008, David A. Bandel wrote:
>On Thu, Dec 4, 2008 at 2:19 AM, Machiel Richards
><MachielR at agilitytech.co.za> wrote:
>> Hi Guys
>>
>>        Here is the details from the administrator of that system:
>>
>> Processes were spawned by the Oracle backup cron (rman).
>>
>> "Any chance the cron could run a second time while the first is running?"
>>
>> This is what happened yes.  The 2nd cron started while the previous one was still running (took longer than 24 hrs).  I then killed the first one, but it left processes behind with parent id 1 (kill -9 doesn't work on them).
>
>OK, you're going to have to write an actual script to run this, write
>a pid file when the process starts, but one line above check for the
>pid file to see if one already exists and exit if it does.  Don't
>forget to remove your pid file when you're done.

Simply checking for the existence of a pid file doesn't take into
account the original process dying or exiting without removing
the pid file.  At least check with a ``kill -0'' on the PID in
the file as I showed in a previous example.

pidfile=/var/run/`basename $0`.pid
[ -s $pidfile ] && {
	kill -0 `cat $pidfile` 2>/dev/null && {
		echo 'some error message still running' 2>&1
		exit 1
	}
	rm -f $pidfile
}
# create new pid file with my process id
echo $$ > $pidfile
# more processing here
rm -f $pidfile

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

We maintain that the very foundation of our way of life is what we call
free enterprise, said Cash McCall, "but when one of our citizens
show enough free enterprise to pile up a little of that profit, we do
our best to make him feel that he ought to be ashamed of himself."
    -- Cameron Hawley



More information about the Linux-users mailing list