Is there a reliable way to kill all the processes of a given user? kill(-1, SIGKILL)
as that user will work, unless a rogue process of that user kills the killing process first. The best I can find so far is to loop through system("ps -u")
for that user and kill the processes that way, but that seems really hacky and inefficient.
EDIT: To clarify, I'm specifically asking for a POSIX-compatable solution. For some reason I thought tagging the question posix would put that in the title.
kill
) have a TOCTOU race condition: between identifying processes to kill and killing them, the process might die and its PID might be recycled. Or new processes owned by that user might come into being, unknown to you.