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:

  1. 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:
      ps aux | grep [username]
      
      Replace [username] with the target user’s username. This will list processes belonging to that user. For example if the user name is ismail use following command.
      ps aux | grep ismail
      
  2. Use sudo to Kill the Process:

    • Once you have the PID, you can kill the process using the kill command with sudo. For example:
      sudo kill [PID]
      
      Replace [PID] with the actual PID of the process. If the process ID is 2314 use the following command.
      sudo kill 2314
      
  3. 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
      
  4. 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]
      

Make sure to use these commands responsibly, as terminating processes can impact other users or system functionality.

© 2024 Linux and Python Tutorials

🌱 Powered by Hugo with theme Dream.