I am just learning bash scripts and very confused right now. I have a JBoss application that runs and every now and again the application starts acting funny and when I look at top and ps- - ef the process I notice two are running. If I kill off the lower PID the application works as designed. The application is call NaviCron and usually I will run this
#
# This script is used to list NaviCron processes
#
echo "NaviCron process list"
#
ps -ef|grep NaviSysCron
echo " "
echo "------------------------------------"
echo " "
echo "JBoss process list"
ps -ef|grep run.sh
echo " "
echo "------------------------------------"
echo " "
exit 0
So I can see if there are more than one process running and if so I’ll kill the lowest PID manually. I know you can do just about anything with scripts so what is the easiest and most efficient way to script this so if there are two processes the script would automagically kill off the lower PID?
Without providing the answer you’re after, keep in mind that the ‘lowest
PID’ doesn’t really mean anything with regard to startup order unless you
haven’t had enough processes to wrap around from the max down to the low
unused numbers again. A better (and probably more-complex) way of doing
this would be to kill either the older process or the newer process,
depending on which one is bad. You may also want to find which process
does NOT have the socket bound for listening and kill that one.
Anyway, just some thoughts before too much time goes into this.
Good luck.
On 05/09/2011 09:36 AM, D8TA wrote:
>
> I am just learning bash scripts and very confused right now. I have a
> JBoss application that runs and every now and again the application
> starts acting funny and when I look at top and ps- - ef the process I
> notice two are running. If I kill off the lower PID the application
> works as designed. The application is call NaviCron and usually I will
> run this
>
> Code:
> --------------------
> #
> # This script is used to list NaviCron processes
> #
> echo “NaviCron process list”
> #
> ps -ef|grep NaviSysCron
> echo " "
> echo “------------------------------------”
> echo " "
> echo “JBoss process list”
> ps -ef|grep run.sh
> echo " "
> echo “------------------------------------”
> echo " "
> exit 0
>
> --------------------
>
>
> So I can see if there are more than one process running and if so I’ll
> kill the lowest PID manually. I know you can do just about anything with
> scripts so what is the easiest and most efficient way to script this so
> if there are two processes the script would automagically kill off the
> lower PID?
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
don’t know whether you already have a solution for your problem and besides the fact ab already wrote, the script you want to run could somehow look like this:
*#!/bin/sh
strProcess=NaviSysCron
while true
do
intProcessid=ps -ef | grep $strProcess | grep -v "grep" | awk '{print $2}' | sort -n | head -n 1
echo $intProcessid # or some kind of (sudo) kill command #break # if script is started manually and should stop after the kill command
sleep 10 # if script runs as an endless loop
done