How to Kill All User Processes Using UID?

In Linux, the multi-users can work simultaneously with different accessibilities. It may be necessary to terminate all processes for the specific user utilizing resources that the administrator does not allow. For that purpose, the administrative user can use their user-ids (UID) or names to kill processes owned by the particular user.

This post will enlighten the methods to kill all user’s processes using their UID in Linux.

  • Method 1: Using the pkill Command
  • Method 2: Using the killall Command | Specify Username 

Method 1: Using the pkill Command

The “pkill” command is considered to kill a user’s processes through the user id. It is the built-in command of Linux that sends the signal to the particular process to exit.

To kill all processes for the particular user id, use the following syntax:

Syntax

$ sudo pkill -9 -U <user-id>

The description of the above syntax is given below:

  • sudo” command allows the root privileges.
  • pkill” command kills the process.
  • 9” option is used to send the termination signal.
  • U” option specifies the “user-id” 

Example: 

The following command kills all the processes of the user id “1001”:

$ sudo pkill -9 -U 1001

All processes for the user id “1001” have been killed.

Method 2: Using the killall Command | Specify Username

Another possible method to kill all user processes by their username is to use the “killall” command. Consider the following command syntax to kill all user’s processes:

Syntax

$ sudo killall -u <username>

The description of the above syntax is presented below:

  • sudo” command is used to allow the root privileges.
  • killall” command kills all processes.
  • u” option is used to specify the “username” 

The subsequent command kills all user’s processes for the user name “Henry”:

$ sudo killall -u Henry

All processes for the username “Henry” have been killed.

To explore more options for the killing processes, follow our article link.

Conclusion

To kill all user processes using their user-id, consider the “pkill”, and “killall” commands to kill all processes by username. The “pkill” command is used with the syntax “sudo pkill -9 -U <user-id>” while the “killall” command is used with the syntax “sudo killall -u <username>”.

This write-up has enlightened the methods to kill all user’s processes by their user-id or username.