* killing a process by name?
@ 1999-06-08 4:00 Christopher Kolar
1999-06-08 4:00 ` Serguei Patchkovskii
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Christopher Kolar @ 1999-06-08 4:00 UTC (permalink / raw)
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.
Problem is that: a) foo has no -kill or similar tag; b) foo does not
drop the process number into a pid file that can be piped into a kill
command.
So my question, is ther a simple way to set up a shell script that
cron can call at midnight that will grep "foo" out of the ps command,
and then kill -PID for foo? I am not much of a shell script
programmer, and only play a system administrator on TV, so those are
two strikes against me. Any help or pointers to the right resources
would be much appreciated.
--chris
--
/////\\\\\/////\\\\\
Christopher G. Kolar
Director of Instructional Technology
Aurora University, Aurora, Illinois
ckolar@aurora.edu -- www.aurora.edu
[Public Key http://certserver.pgp.com:11371/pks/lookup2?op=index&search=0x5B61A799]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: killing a process by name?
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
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Serguei Patchkovskii @ 1999-06-08 4:00 UTC (permalink / raw)
Christopher Kolar (ckolar@aurora.edu) wrote:
: So my question, is ther a simple way to set up a shell script that
: cron can call at midnight that will grep "foo" out of the ps command,
: and then kill -PID for foo? I am not much of a shell script
How about:
ps -eo pid,command|awk '$2=="foo"{print$1}'|xargs -n1 kill
/Serge.P
--
home page: http://www.cobalt.chem.ucalgary.ca/ps/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: killing a process by name?
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
1999-06-09 4:00 ` Adam Price
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Mark Lambert @ 1999-06-09 4:00 UTC (permalink / raw)
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.
>
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}'`
that is:
kill (the numbers returned from the ``comand):
ps piped into a grep for foo, then discard the process running the grep
command, pipe the resulting ps line(s) into awk printing only the PID field.
Have fun!
--
/\ The Fulcrum Consulting Group Mark Lambert - Consultant
/\O\ Professional Services For Operation Mark.Lambert@fulcrum.com.au
/ /\ Of A Networked Computing Environment ph: +61-3-9621-2100
/o | \ 12/10-16 Queen St, Melbourne VIC 3000, Australia fx: +61-3-9621-2724
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: killing a process by name?
1999-06-08 4:00 killing a process by name? Christopher Kolar
` (2 preceding siblings ...)
1999-06-09 4:00 ` Adam Price
@ 1999-06-09 4:00 ` Javier de Burgos
1999-06-09 4:00 ` Jeff Denham
4 siblings, 0 replies; 10+ messages in thread
From: Javier de Burgos @ 1999-06-09 4:00 UTC (permalink / raw)
Christopher Kolar wrote:
> Foo should run until midnight, when
> it needs to be killed so that out nightly backups can happen.
>
> Problem is that: a) foo has no -kill or similar tag; b) foo does not
> drop the process number into a pid file that can be piped into a kill
> command.
Add to you crontab the following line:
00 0 * * * kill `ps aux | grep foo | tr -s " " | cut -d " " -f2`
Easy?
Regards
--
Un saludo,
Javier AKA jdeburgos@NOSPAMcanal21.com AKA 2:341/53.51@fidonet.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: killing a process by name?
1999-06-09 4:00 ` Mark Lambert
@ 1999-06-09 4:00 ` Paul David Fardy
0 siblings, 0 replies; 10+ messages in thread
From: Paul David Fardy @ 1999-06-09 4:00 UTC (permalink / raw)
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 |
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: killing a process by name?
1999-06-08 4:00 killing a process by name? Christopher Kolar
` (3 preceding siblings ...)
1999-06-09 4:00 ` Javier de Burgos
@ 1999-06-09 4:00 ` Jeff Denham
1999-06-16 4:00 ` Tim Mooney
4 siblings, 1 reply; 10+ messages in thread
From: Jeff Denham @ 1999-06-09 4:00 UTC (permalink / raw)
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.
>
> Problem is that: a) foo has no -kill or similar tag; b) foo does not
> drop the process number into a pid file that can be piped into a kill
> command.
>
> So my question, is ther a simple way to set up a shell script that
> cron can call at midnight that will grep "foo" out of the ps command,
> and then kill -PID for foo? I am not much of a shell script
> programmer, and only play a system administrator on TV, so those are
> two strikes against me. Any help or pointers to the right resources
> would be much appreciated.
Well, it's really too bad that this Compaq Unix thing doesn't
have a decent proc tools offering, like Solaris 7 does.
There you can just use the pkill command to select
processes by name using regular expression matching
and send them the signal of your choice.
Shame on you Compaq!
__________________________________________________
Jeff Denham (jdenham@allaire.com)
Allaire Corp: Resource-management software
for building and managing fast, reliable web sites
See us at http://www.allaire.com and http://www.brighttiger.com
125 Nagog Park
Acton, MA 01720
Phone: (978) 263-5455 x177
Fax: (978) 263-5547
;^)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: killing a process by name?
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 ` Adam Price
1999-06-10 4:00 ` Bruno KRINER
1999-06-09 4:00 ` Javier de Burgos
1999-06-09 4:00 ` Jeff Denham
4 siblings, 1 reply; 10+ messages in thread
From: Adam Price @ 1999-06-09 4:00 UTC (permalink / raw)
Christopher Kolar wrote in message
<375d6a41.14695581@news.aurora.edu>...
>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.
>
>Problem is that: a) foo has no -kill or similar tag; b) foo does
not
>drop the process number into a pid file that can be piped into a
kill
>command.
>
>So my question, is ther a simple way to set up a shell script
that
>cron can call at midnight that will grep "foo" out of the ps
command,
>and then kill -PID for foo? I am not much of a shell script
>programmer, and only play a system administrator on TV, so those
are
>two strikes against me. Any help or pointers to the right
resources
>would be much appreciated.
>
Others will tell you about ps and grep, but an alternative is to
use a shell script to start the job and record it's PID in a
file. This pid can be used to kill your job.
Hope this helps
Adam
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: killing a process by name?
1999-06-09 4:00 ` Adam Price
@ 1999-06-10 4:00 ` Bruno KRINER
0 siblings, 0 replies; 10+ messages in thread
From: Bruno KRINER @ 1999-06-10 4:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1561 bytes --]
One manner to do this could be :
kill `/sbin/init.d/bin/getpid process-name-with-path-such as-it-appears-in-ps \
-u process-owner`
It works !
Regards
>
>Christopher Kolar wrote in message
><375d6a41.14695581@news.aurora.edu>...
>>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.
>>
>>Problem is that: a) foo has no -kill or similar tag; b) foo does
>not
>>drop the process number into a pid file that can be piped into a
>kill
>>command.
>>
>>So my question, is ther a simple way to set up a shell script
>that
>>cron can call at midnight that will grep "foo" out of the ps
>command,
>>and then kill -PID for foo? I am not much of a shell script
>>programmer, and only play a system administrator on TV, so those
>are
>>two strikes against me. Any help or pointers to the right
>resources
>>would be much appreciated.
>>
>
>Others will tell you about ps and grep, but an alternative is to
>use a shell script to start the job and record it's PID in a
>file. This pid can be used to kill your job.
>
>Hope this helps
>Adam
>
>
>
---
B. Kriner
Centre d'Etudes de la Navigation A�rienne (CENA)
7,Av. Edouard Belin BP4005 31055 Toulouse Cedex
Tel: (33) (0)5 62 25 95 40
Fax: (33) (0)5 62 25 95 99
E-mail: kriner@cena.fr
http: //www.tls.cena.fr/~kriner
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: killing a process by name?
1999-06-09 4:00 ` Jeff Denham
@ 1999-06-16 4:00 ` Tim Mooney
1999-06-16 4:00 ` Jeff Denham
0 siblings, 1 reply; 10+ messages in thread
From: Tim Mooney @ 1999-06-16 4:00 UTC (permalink / raw)
In article <375E6296.57AAAE0C@allaire.com>,
Jeff Denham <jdenham@allaire.com> wrote:
> Christopher Kolar wrote:
>
> Well, it's really too bad that this Compaq Unix thing doesn't
> have a decent proc tools offering, like Solaris 7 does.
> There you can just use the pkill command to select
> processes by name using regular expression matching
> and send them the signal of your choice.
>
> Shame on you Compaq!
Jeff-
If you want to take Compaq to task for something, not having pgrep and pkill
a la Solaris 7 is something pretty minor, wouldn't you say! ;-) . I can
think of lots of things that I think should be a higher priority than having
some Compaq engineer write a C program to do something that I can already
accomplish (albeit with a few extra forks and popens) using a pipeline of
standard Unix commands.
Tim
--
Tim Mooney mooney@dogbert.cc.ndsu.NoDak.edu
Information Technology Services (701) 231-1076 (Voice)
Room 242-J1, IACC Building (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: killing a process by name?
1999-06-16 4:00 ` Tim Mooney
@ 1999-06-16 4:00 ` Jeff Denham
0 siblings, 0 replies; 10+ messages in thread
From: Jeff Denham @ 1999-06-16 4:00 UTC (permalink / raw)
Tim Mooney wrote:
> In article <375E6296.57AAAE0C@allaire.com>,
> Jeff Denham <jdenham@allaire.com> wrote:
> > Christopher Kolar wrote:
> >
> > Well, it's really too bad that this Compaq Unix thing doesn't
> > have a decent proc tools offering, like Solaris 7 does.
> > There you can just use the pkill command to select
> > processes by name using regular expression matching
> > and send them the signal of your choice.
> >
> > Shame on you Compaq!
>
> Jeff-
>
> If you want to take Compaq to task for something, not having pgrep and pkill
> a la Solaris 7 is something pretty minor, wouldn't you say! ;-) . I can
> think of lots of things that I think should be a higher priority than having
> some Compaq engineer write a C program to do something that I can already
> accomplish (albeit with a few extra forks and popens) using a pipeline of
> standard Unix commands.
Sorry, Tim. Bad inside joke, with the smiley placed too far
down the message. I used to work there and support the
/proc fs among other things...
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~1999-06-16 4:00 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
1999-06-09 4:00 ` Adam Price
1999-06-10 4:00 ` Bruno KRINER
1999-06-09 4:00 ` Javier de Burgos
1999-06-09 4:00 ` Jeff Denham
1999-06-16 4:00 ` Tim Mooney
1999-06-16 4:00 ` Jeff Denham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox