Jump to content

Kill process by command name

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
mop

mop

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
I logged onto my server this morning and it was running incredibly slow. I had no idea wtf was causing the problem so I executed top and sorted by memory. I found this:

 7298 customa  18   0  492M 492M  3768 S     0.0 12.3   0:08   1 java
 7300 customa  15   0  492M 492M  3768 S     0.0 12.3   1:58   2 java
 7301 customa  15   0  492M 492M  3768 S     0.0 12.3   1:58   7 java
 7302 customa  15   0  492M 492M  3768 S     0.0 12.3   1:58   5 java
 7303 customa  15   0  492M 492M  3768 S     0.0 12.3   1:58   1 java
 7304 customa  16   0  492M 492M  3768 S     0.0 12.3   1:57   6 java
 7305 customa  15   0  492M 492M  3768 S     0.0 12.3   1:58   3 java
 7306 customa  16   0  492M 492M  3768 S     0.0 12.3   1:58   4 java
 7307 customa  16   0  492M 492M  3768 S     0.0 12.3   1:58   3 java
 7308 customa  15   0  492M 492M  3768 S     0.0 12.3  15:59   5 java
 7309 customa  15   0  492M 492M  3768 S     0.0 12.3   0:07   4 java
 7310 customa  15   0  492M 492M  3768 S     0.0 12.3   0:10   6 java
 7311 customa  25   0  492M 492M  3768 S     0.0 12.3   0:00   4 java
 7312 customa  15   0  492M 492M  3768 S     0.0 12.3   0:00   3 java
 7313 customa  15   0  492M 492M  3768 S     0.0 12.3   0:32   7 java
 7314 customa  16   0  492M 492M  3768 S     0.0 12.3   0:38   6 java
 7315 customa  25   0  492M 492M  3768 S     0.0 12.3   0:00   4 java
 7316 customa  15   0  492M 492M  3768 S     0.0 12.3  11:11   0 java
 7320 customa  25   0  492M 492M  3768 S     0.0 12.3   0:00   0 java
 7578 customa  15   0  492M 492M  3768 S     0.0 12.3   1:00   4 java
 7585 customa  15   0  492M 492M  3768 S     0.0 12.3   2:19   5 java
 7586 customa  15   0  492M 492M  3768 S     0.0 12.3   2:11   1 java
 7587 customa  15   0  492M 492M  3768 S     0.0 12.3   2:21   3 java
 7588 customa  15   0  492M 492M  3768 S     0.0 12.3   2:16   3 java
 7589 customa  15   0  492M 492M  3768 S     0.0 12.3   2:10   2 java
 7590 customa  15   0  492M 492M  3768 S     0.0 12.3   2:13   6 java
 7591 customa  15   0  492M 492M  3768 S     0.0 12.3   2:12   4 java
 7592 customa  15   0  492M 492M  3768 S     0.0 12.3   2:13   0 java
 7593 customa  15   0  492M 492M  3768 S     0.0 12.3   2:19   0 java
 7594 customa  15   0  492M 492M  3768 S     0.0 12.3   2:14   4 java
 7595 customa  15   0  492M 492M  3768 S     0.0 12.3  49:32   5 java
 7599 customa  15   0  492M 492M  3768 S     0.0 12.3   1:03   3 java
 7603 customa  15   0  492M 492M  3768 S     0.0 12.3   1:00   4 java
 7608 customa  15   0  492M 492M  3768 S     0.0 12.3   0:00   2 java

So, how can I killl all process that are executing Java?

#2
ToRk

ToRk

    Newbie

  • Members
  • Pip
  • 9 posts
Hello

try
killall -v java
ed3mny.com

#3
Tor

Tor

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 486 posts
When I look at the killall command I see: -v,--verbose report if the signal was successfully sent

Not sure how killall -v java would help him in this case.

#4
ToRk

ToRk

    Newbie

  • Members
  • Pip
  • 9 posts
yes you are right , sorry for this mistake
i recheck & almost nothing kill process by name
ed3mny.com

#5
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I don't think there is a default method to kill by name. You could write a shell script to do it though.

#6
Corwin

Corwin

    Newbie

  • Members
  • PipPip
  • 12 posts
in additional you can try to kill with "-12" this will try to shutdown proper the application

#7
Roger

Roger

    If nothing goes right, go left.

  • Administrators
  • 718 posts
I normally do 'ps aux' and 'kill -9' the PID

#ps aux

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

Edited by Roger, 27 June 2010 - 06:17 PM.


#8
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts

dspin08 said:

I normally do 'ps aux' and 'kill -9' the PID

A more apt and simple method, to kill all processes by the process' name:
killall -9  Java
Note it will kill all open processes of the programme, if you would wish for it to be more specific:

killall -9 Java -u customa

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#9
sea

sea

    Newbie

  • Members
  • Pip
  • 7 posts
This is already answered by the guy above me, but you should know about 'pkill', it kills a process by name. I think you can also use regexp in the name, too.
Check the manpages for it.
example: pkill -9 java;


#10
phpforfun

phpforfun

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,236 posts
kill -9 $(ps -e |grep "httpd" | awk '{print $1;}')

or

killall -9 httpd

assuming httpd is the service you wanna kill.
Checkout my new forum! http://adminreference.com/

#11
DesperD0s

DesperD0s

    Newbie

  • Members
  • Pip
  • 7 posts
Yes, you can kill any process with name by using this command :
If you want to know what signal to kill first type kill -l. It will show up you complete list of the signals.
If you want to know what process to kill type ps -e --forest(Although there are many others, but this will suit you just fine).
$ killall -s[SIGNAL] <nameOfYourPRocess>
$ killall -TERM <nameOfYourPRocess> process may ignore this signal.
$ killall -HUP <nameOfYourPRocess> process will be done in bg after hang up
$ killall -INT <nameOfYourPRocess> interrupt signal controled by an INTR.
$ killall -QUIT <nameOfYourPRocess> interactive abolition of the processes controlled by an QUIT.
$ killall -KILL <nameOfYourPRocess> last thing you want to do, belive me.
or
kill -s[signal] PID.

Now, besides this, there are many other commands to kill the process or signal, like stty -a[you get list how to kill fg processes]...

Also there are many "controlling" commands for the processes like STOP, CONT, TSTP, TTIIN, TTOU ...