Pages

30 March 2012

Killing Java Process Instances on Linux

Almost all IT teams and companies, that uses enterprise java technologies on application servers or servlet containers, prefers running their systems on free or enterprise LINUX distributions. I am using an IBM AIX that hosts an IBM WebSphere Application Server for testing applications. Sometimes, restarting is unavoidable when OutOfMemoryError occurs due to frequent deployments on WAS. Anytime stopping all servers, nodes and deployment manager instances with using prepared batches in server installation directory.

./was/bin/stopServer.sh "server-name" -username "user-name" -password "password"
... 
./was/bin/stopNode.sh -username "user-name" -password "password"
... 
./was/bin/stopManager.sh -username "user-name" -password "password"


Instead of that, I wrote an SH script to kill all active processes that contains "java" keyoword in their names.

#!/bin/sh
# retrieving active java instances' processIds
java_pids=$(ps -e | grep java | awk '{ print $1}')

# kill each  process id with "kill -9"
for java_pid in $java_pids
do
 echo "killing java process $java_pid"
 kill -9 $java_pid
done
## end of sh


take care.