0

Situation

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.

Problem

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 ?

1
  • 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).
    – user313992
    Commented Apr 15, 2020 at 5:33

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .