Skip to content

Instantly share code, notes, and snippets.

@Viroide
Last active December 30, 2015 10:55
Show Gist options
  • Select an option

  • Save Viroide/22cf5006925cadabc461 to your computer and use it in GitHub Desktop.

Select an option

Save Viroide/22cf5006925cadabc461 to your computer and use it in GitHub Desktop.
Kills older java process that are in the server
killOldersJava(){
javaProcessNumer=`ps -ej | grep java | wc -l`
while [ $javaProcessNumer -gt 1 ]
do
PID=`ps -ej --sort=start_time | grep java | head -n1 | awk '{ print $1 }'`
echo "More than one java process, killing the older PID=$PID"
kill -9 $PID
javaProcessNumer=`ps -ej | grep java | wc -l`
done
PID=`ps -ej --sort=start_time | grep java | head -n1 | awk '{ print $1 }'`
echo "Only one java process PID=$PID , nothing to kill"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment