Aliases to Kill Linux Processes
Writing by shivdev on Wednesday, 20 of April , 2011 at 9:30 pm
As a developer I’m constantly restarting processes. For instance, if I have 2 Java Process (Server/Web) and an Eclipse Java Process which makes 3 Java Processes. The problem is to kill only the server and web processes and leave the eclipse java process intact.
Solution 1 (The Hard and Manual approach):
Find the java processes and kill them manually
ps -ef | grep java
kill -9 1
kill -9 2
Solution 2 (The Simplified Approach – killjava):
Create an alias or run the following:
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/”|xargs kill -9
This will kill all java processes – which means you will need to restart eclipse each time you run this.
Solution 3 (The Tuned Approach – killweb):
Create an alias or run the following based on a keyword (say, Web process remote_debug port 4096):
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/” | xargs ps -p | grep 4096 | sed -e “s/\s*\([0-9]*\).*/\1/” | xargs kill -9Create an alias or run the following based on a keyword (say, Server process remote_debug port 2048):
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/” | xargs ps -p | grep 2048 | sed -e “s/\s*\([0-9]*\).*/\1/” | xargs kill -9This will kill only the specific processes you want to terminate.
Solution 4 (The BEST Way – Combine 1 and 2 in a single alias – killdebug):
Create an alias or run the following (Use egrep to look for multiple keywords above):
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/” | xargs ps -p | egrep “2048|4096” | sed -e “s/\s*\([0-9]*\).*/\1/” | xargs kill -9
This will kill all processes you WISH to terminate.
I have aliases for Solutions 2, 3 and 4 depending on what I’m trying to do. So there you go – hope that helps!
Leave a comment
Category: Linux,Tips and Tricks
- Add this post to
- Del.icio.us -
- Digg -
- -
- Tweet -
-
-
No comments yet.
You must be logged in to post a comment.