pkill command with sessionid is not killing entire process tree

I am executing the following command to stop entire process tree(i.e parent and all its child/grand-child processes) :

pkill -9 -s {sessionID}

To get sessionID I am using following command:

ps -o pid,sess -u <username> | grep <pid> | awk '{print $2}'

Sometimes pkill command kills entire process tree, but sometimes it doesn't work. Some of the child process still be running in background. Why is that so? Is there anything wrong in my logic? Is there any boundary condition missing? Are there any situations where pkill command doesn't kill child processes?

1

1 Answer

A process' children need not necessarily share its session ID. If that were the case, every process would have session ID 1. You can also try using process group IDs, but that too has the same limitation.

Walking through the process tree has the limitation that double-forked processes aren't part of the tree anymore, but might be your best bet. Examples of this method:

6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like