Linux – Killing all processes of current user

killlinuxprocess

user@host$ killall -9 -u user

Will it definitely kill all processes owned by user (including forkbombs)?

  1. No new processes is spawned to user from other users.
  2. No user's processes are in D-sleep and unkillable.
  3. No processes are trying to detect and ptrace or terminate this started killall (but they can ptrace or do other things with each other)
  4. There is ulimit that prevents too much processes (but killall is already started and allocated it's memory)

E.g. if killall will finish untampered and successfully is it 100% that no processes are left with this uid? If no, how to do it properly (with standard commands and no root access).

Will SysRq+I definitely kill all things (even replicating)?

Best Answer

No. killall first lists all processes that are to be killed, and then iterates through that list and kills them. If you have a forkbomb running, after killall will kill one of its processes, it is very likely that another process will immediately reclaim PID which has just freed, but killall thinks it already killed that process, so effectively nothing will happen.

You should use ulimit if a forkbomb is a problem for you. Limit number of processes to, for example, 128, and a forkbomb will silently die or stop expanding, depending on how it was written. Anyway, it will not present any danger to other users of that system.