1

I want to kill a process in Ubuntu.

I have Java installed and Running JBOSS & Tomcat at background. I need to kill Tomcat after deployment but when I kill it JBOSS is going too.

I had to use

kill -9 pidofjava
killall tomcat

But status is still same.

What I need to do to kill a process attribute? I mean subprocess?

N.N.
  • 18,589

2 Answers2

1

You can loop through the process list, identifying children with the same parent and kill them one by one.

Attribution: http://www.unix.com/17901-post4.html

#!/bin/sh
while true
do
  echo "Enter parent process id  [type quit for exit]"
  read ppid

  if [ $ppid -eq "quit" -o $ppid -eq "QUIT" ];then
     exit 0
  fi

  for i in `ps -ef| awk '$3 == '$ppid' { print $2 }'`
  do
      echo killing $i
      kill $i
  done
done

You can also kill by session id but that get's the parent and the children.

https://serverfault.com/questions/40303/how-do-you-kill-a-process-tree-in-linux

ps -eo pid,ppid,sess,cmd -u ppetraki | grep whoami

pkill -9 -s SESS_ID

Using the information from the later, you could build a simpler tool that targeted only children.

ppetraki
  • 5,531
1

Usually processes check whether their subprocesses are still alive and might shut down themselves if one of the subprocesses is aborted.

Michael K
  • 14,338