Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: pdf@morgan.ucs.mun.ca (Paul David Fardy)
Subject: Re: killing a process by name?
Date: 1999/06/09	[thread overview]
Message-ID: <7jln65$ss1$1@coranto.ucs.mun.ca> (raw)
In-Reply-To: 375DBA80.76E3B5FA@fulcrum.com.au

Christopher Kolar wrote:
>> Hello everyone.  This is probably a basic question, but I have not
>> found the solution yet so I thought I would float it.  I have a host
>> running OSF 4.0d.  After everyone leaves for the day I am going to
>> have cron start a program "foo".  Foo should run until midnight, when
>> it needs to be killed so that out nightly backups can happen.

Mark Lambert <markl@fulcrum.com.au> writes:
>Serguei Patchkovskii had a more elegant awk solution, but mine is (I think)
>more understandable for non-awk guru's...
>the brute force approach :0
>try
>kill `ps -ef | grep foo | grep -v grep | awk '{print $2}'`

Danger!  Will Robinson!  Danger!   :-)

Is this cron job to run as root?   What if I'm running an important job?

	/local/sbin/food -for the-hungry

Will they not starve?

One should ensure not "foo", but the complete path (e.g. "/local/sbin/foo")
appears in the process table.  Then one should test for equality, using
something like the awk solution provided by Serguei.  You could also use

	0 0 * * * kill `/sbin/init.d/bin/getpid /local/sbin/foo`

The getpid script is used by the init.d (rc2.d and rc3.d) scripts when
the relevant daemons aren't using /var/run.  It provides a variant of
Serguei's solution.

One still might worry about multiple instances...

Perhaps it would be better to wrap your program with a script like:

	#!/bin/sh
	echo $$ > /var/run/foo.pid
	exec /local/sbin/foo

and use 

	0 0 * * * kill `cat /var/run/foo.pid`

though this will fail if foo forks a new process and exits.

Paul Fardy
-- 
Paul David Fardy                      |  pdf@morgan.ucs.mun.ca
Computing and Communications          |  pdf@InfoNET.st-johns.nf.ca
Memorial University of Newfoundland   |
St. John's, NF  A1C 5S7               |



  reply	other threads:[~1999-06-09  4:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-08  4:00 killing a process by name? Christopher Kolar
1999-06-08  4:00 ` Serguei Patchkovskii
1999-06-09  4:00 ` Mark Lambert
1999-06-09  4:00   ` Paul David Fardy [this message]
1999-06-09  4:00 ` Adam Price
1999-06-10  4:00   ` Bruno KRINER
1999-06-09  4:00 ` Jeff Denham
1999-06-16  4:00   ` Tim Mooney
1999-06-16  4:00     ` Jeff Denham
1999-06-09  4:00 ` Javier de Burgos
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox