How to Kill Other Users Processes With Sudo Privileges
Saturday, Aug 3, 2024 | 2 minutes read | Update at Saturday, Aug 3, 2024
Linux is multi user system where multiple users can use it at the same time. This means there may be multiple processes running by different users. Some time we may need to stop or kill another users processes. For example if another user running a process which locked a file and we need to access this file we can remove the file lock by killing other user’s process. In order to kill other user process we should have higher privileges than that user. If we are root user we can easily kill other users process. Alternatively we can use the sudo command which simply provides the root privileges with the regular user session. To kill another user’s process with sudo
privileges, follow these steps:
-
Find the Process ID (PID):
- You need to identify the PID of the process you want to terminate. Use the
ps
command to list processes. For example, you can use:Replaceps aux | grep [username]
[username]
with the target user’s username. This will list processes belonging to that user. For example if the user name isismail
use following command.ps aux | grep ismail
- You need to identify the PID of the process you want to terminate. Use the
-
Use
sudo
to Kill the Process:- Once you have the PID, you can kill the process using the
kill
command withsudo
. For example:Replacesudo kill [PID]
[PID]
with the actual PID of the process. If the process ID is 2314 use the following command.sudo kill 2314
- Once you have the PID, you can kill the process using the
-
Force Kill (if needed):
- Sometime the kill command may not work properly with default options. We can foce the termination with the force option. If the process does not terminate with a normal
kill
command, you can forcefully kill it using the-9
option:sudo kill -9 [PID]
sudo kill -9 2314
- Sometime the kill command may not work properly with default options. We can foce the termination with the force option. If the process does not terminate with a normal
-
Verify the Process is Terminated:
- After we terminated the process we can check if the process has been successfully terminated by running:
ps aux | grep [username]
- After we terminated the process we can check if the process has been successfully terminated by running:
Make sure to use these commands responsibly, as terminating processes can impact other users or system functionality.