unix command: killing process id with ps

unix command: killing process id with ps

Post by Sam Wu » Thu, 08 Nov 2001 11:52:50



hi,

I know the kill command can kill a process ID, but it is normally done by
two command: firstly show the proc id and then kill. Does any one know how
to do it in a single command line? ie. kill -HUP | ps ..... inet ??

Thanks
Sam

 
 
 

unix command: killing process id with ps

Post by Devon Rya » Thu, 08 Nov 2001 12:08:00



> hi,

> I know the kill command can kill a process ID, but it is normally done by
> two command: firstly show the proc id and then kill. Does any one know how
> to do it in a single command line? ie. kill -HUP | ps ..... inet ??

Well you could do a ps and pipe it to grep, then awk, then kill.  You
might look at killall.  It may have the functionality that you're
looking for.

--

Biology/Neuroscience, Pre-med | http://home.uchicago.edu/~dpryan



 
 
 

unix command: killing process id with ps

Post by yhp » Thu, 08 Nov 2001 12:25:44



>  hi,

   hello,

Quote:>  I know the kill command can kill a process ID, but it is normally done by
>  two command: firstly show the proc id and then kill. Does any one know how
>  to do it in a single command line? ie. kill -HUP | ps ..... inet ??

   Maybe:
   ~# ps aux | grep inet | awk '{print $2}' | xargs kill -HUP

   But, there is 'skill' (/usr/ports/sysutils/skill) that you can use by
giving the name of the process instead of PID:
   ~# skill -HUP inet

regards,
--
               I believe the technical term is "Oops!"

 
 
 

unix command: killing process id with ps

Post by Stephen Montgomery-Smit » Thu, 08 Nov 2001 12:41:46



> hi,

> I know the kill command can kill a process ID, but it is normally done by
> two command: firstly show the proc id and then kill. Does any one know how
> to do it in a single command line? ie. kill -HUP | ps ..... inet ??

killall -HUP inetd

does what you want.

--
Stephen Montgomery-Smith

http://www.math.missouri.edu/~stephen

 
 
 

unix command: killing process id with ps

Post by Brian K. Whit » Thu, 08 Nov 2001 12:44:08



Quote:> hi,

> I know the kill command can kill a process ID, but it is normally done by
> two command: firstly show the proc id and then kill. Does any one know how
> to do it in a single command line? ie. kill -HUP | ps ..... inet ??

> Thanks
> Sam

in general, no.
a human has to look at the whole line of ps output to decide what is the
right process, and the decision is based on different criteria every time.
in one case you may need to kill a login shell and all it's children but not
any other shells or any other instances of the children.

in another case you may need to kill any process attached to a particular
tty

or any process that has anything to do with the X server...

in the simplest case, if you know for a fact that there is only one instance
of a particular program, and you know exactly how to regexp for that program
in the list, then you could do something like this:

kill -HUP `ps -ef |awk '($8 == "theprogram"){print $2}'`

which means, if field 8 is "theprogram" then kill the process number in
field 2

but this is unsafe, even though I have provided a more precise example here
than some others you would see if you had searched google groups for "awk
kill"

which all go like:

kill -HUP `ps -ef |awk '/theprogram/{print $2}'`

which means if "theprogram" occurs anywhere in the line, then print field 2,
and kill tries to kill it. this is more likely to get the wrong line, or get
multiple lines.

basically if you can write a script that parses the output of ps and spits
out a single pid, then you can do "kill -HUP `script`" but what that script
amounts to depends entirely on criteria only you know such as what exactly
do you need to kill?
there is no one size fits all answer.

bahh, those were sco unix examples, here is the equivalent on freebsd:
(looking for lpd in this case)

kill -HUP `ps auxwww | awk '($11 == "/usr/sbin/lpd"){print $2}'`

--

+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx  Linux SCO  Prosper/FACTS AutoCAD  #callahans Satriani

 
 
 

unix command: killing process id with ps

Post by Daniel Rud » Thu, 08 Nov 2001 15:02:21



> hi,

> I know the kill command can kill a process ID, but it is normally done by
> two command: firstly show the proc id and then kill. Does any one know how
> to do it in a single command line? ie. kill -HUP | ps ..... inet ??

> Thanks
> Sam

Most system daemons store their PID in /var/run If you were looking to
kill natd, you would use kill -15 `cat /var/run/natd.pid`
--
Daniel Rudy
Reply to dcrudy at aol dot com.

*!*!* DO NOT HIT REPLY *!*!*
ALL EMAIL SENT TO REPLY ADDRESS WILL BE DELETED!

 
 
 

unix command: killing process id with ps

Post by David Malo » Thu, 08 Nov 2001 19:15:33



>I know the kill command can kill a process ID, but it is normally done by
>two command: firstly show the proc id and then kill. Does any one know how
>to do it in a single command line? ie. kill -HUP | ps ..... inet ??

If you want to kill -HUP all processes whose ps output has the word
"luser" in it, you can do:

        kill -HUP `ps -auxwww | awk '/luser/ { print $2 }'

If you want to kill -HUP all the processes called inetd you can
do:

        killall -HUP inetd

David.

 
 
 

1. Piping process IDs into kill command

        I have worked out the following command that displays PID
numbers for processes involving a script (in tcsh) named .filebif:

ps -g |grep .filebif |grep '[0-9]*[0-9]*[0-9]*[0-9]*[0-9]*' |cut -c1-5

        Which results in output like this:

 5473
27483

        I would like to then execute a kill command with the first, or
both, of these numbers as arguments, but haven't figured out how to
automate this.  If I could pipe them into a variable (using tcsh syntax:
"set var=value"), I could issue a "kill $var", but don't know how to get
command output into a variable.  Or perhaps there is a more direct syntax
to feed them to "kill" without needing a variable?  Advice appreciated.

                                                        --Donald Davis

2. Linux Graphical Frontends

3. Is there a command to get the status of a particular Process ID (not ps)

4. Setting up a Linux Box as a Firewall for Win9x?

5. Increase root slice on Ultra1 5.5.1

6. how to kill a process extracted from ps command?

7. Printing via GhostScript

8. Unix PS Unix Kill

9. How can kill all child processes without killing parent process ?

10. A method to kill process that cannot be killed even with `kill -9'.

11. How to kill process which not killed by 'kill' ?

12. Newbie. find and kill by parent process id