I have set up an environment where users can login from multiple endpoints and use tmux, screen ... so when they end their work they can either logout of their ssh session which doesn't kill any process kept in any terminal multiplexer, they can either do a pkill -u ${USER} or killall -u ${USER} to kill all their process, for that I wrap the function inside a script named fulllogout.


When running pkill -u ${USER} or killall -u ${USER}, the killing process can kill itself or it's shell before killing all other processes which result in some process kept alive.

How can I do it successfully without allowing elevated rights ?

  • 2
    pkill doesn't kill itself. Your problem is probably that some processes are ignoring the TERM signal (eg. interactive shells), or are stopped, in which case the signal will only reach them if woken up. "Elevated rights" will not help with any of those. I suggest you do a fulllogout()( pkill -HUP -u "$USER"; pkill -CONT -u "$USER"; pgrep -u "$USER" && { sleep 10; pkill -KILL -u "$USER"; } &) instead (untested). – mosvy Apr 15 '20 at 5:33

kill -TERM -1 will send SIGTERM to every process it had permission to do so (except pid 1), likewise kill -KILL -1 will kill everything possible. This is done in a single system call so can not kill itself part way through.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.