On November 11, 2003 04:43 pm, Peter Van den Wildenbergh wrote:
>
> Hi all:
>
> On one of our servers we start of a bunch of java processes which by
> them selves spawn off a couple other java VM's.
>
> A partial result of pstree :
>
> |-java(23094) -showversion -Xms512m -Xmx512m -classpath /home/ikermit/train/appl
> | `-java(23125) -showversion -Xms512m -Xmx512m -classpath /home/ikermit/train/appl
> | |-java(23126) -showversion -Xms512m -Xmx512m -classpath
> /home/ikermit/train/appl
> | |-java(23127) -showversion -Xms512m -Xmx512m -classpath
> /home/ikermit/train/appl
> | |-java(23128) -showversion -Xms512m -Xmx512m -classpath
> /home/ikermit/train/appl
> | |-java(23129) -showversion -Xms512m -Xmx512m -classpath
> /home/ikermit/train/appl
> | |-java(23130) -showversion -Xms512m -Xmx512m -classpath
> /home/ikermit/train/appl
>
> The problem is that for some (yet) unidentified reason the parent
> process dies but the underlaying childeren keep on going.
>
> Is there a way (script in cron job) to detect this ?
>
> Thanks
>
> Peter
>
>
Hi,
If your child java processes are orphaned (parent is completely gone) then
they should be adopted by init (process #1). You should be able to use
ps to look for java processes with a parent pid of 1 and just kill them.
Maybe something like this would work for you:
$ ps -eo ppid,pid,args h | gawk '/java/ { if($1=="1") print $2 }' | xargs kill
It lists the parent process id, process id, and command of all processes and
passes the lines to gawk. gawk looks for java in the line and if it exists
it checks that the parent process id ($1) is "1" for init. If so, gawk
prints out the process id ($2). All the process ids are piped into xargs
which calls kill with each process id received from gawk. Leave off that last
bit if you don't actually want to kill the processes.
Regards,
~Scott