I can't seem to find any examples on the internet for this particular task.
3 Answers
You can do this either via:
for i in $(pgrep -U $UID_OF_ANOTHER_USER); do kill -9 $i; done
OR
pkill -U $UID_OF_ANOTHER_USER
You can use the first one to do something more other than just killing those processes, like listing all of them while killing.

- 185
-
1As $UID is the user id of the current user. This will kill your own processes. In addition, it may kill itself before finishing. – ctrl-alt-delor May 27 '18 at 11:34
Here is a simple solution, that will work if you are root.
su $uid -c kill SIGSTOP -1
Explanation: become that user, and kill everything that you can.
All solutions will require CAP_KILL (permission to kill any process), or to be traditional root (root has this permission), and permission (capability to change its own uid), as used by this solution.
Note I sent sigstop, this will pause the process (as asked for ☺). Chose the signal that you want. Use sigkill as last resort.

- 27,993
killall -u $user -STOP
This is safe if run as another user and (for other signals) if no parent process belongs to the affected user.
ctrl-alt-delor's solution is probably better (safer). This one has the advantage of giving you a real exit code, though. The other one probably does not as both su
and kill
get killed themselves.

- 90,279
for i in $(pgrep -U $UID); do kill -9 $i; done
orpkill -U $UID
whichever seems suitable, replace $UID with the required UID or just assign it a value beforehand. – Kunal Gupta May 27 '18 at 08:06