Skip to content

Identify the user running a process on server by using its PID

You can easily identify the user running a process using its PID. The most common and direct method is with the ps command.

🖥️ Using the ps Command (Recommended)

This is the simplest way to get the information. You can either get just the username or a full listing with more details.

1. To get only the username:

Open your terminal and run the following command, replacing 1698110 with your PID:

Bash

ps -o user= -p 1698110
  • -o user= specifies that you only want to see the output for the user column, without a header.
  • -p 1698110 tells ps to look for the specific process with that PID.

2. To get more detailed information:

If you want to see the user along with other process details like the full command, use this command:

Bash

ps -f -p 1698110
  • -f provides a “full-format” listing.

You’ll get an output similar to this, where the user is listed in the first column (UID):

UID          PID    PPID  C STIME TTY          TIME CMD
username    1698110 1698098  0 15:30 ?        00:00:05 /path/to/process/name

📁 Using the /proc Filesystem

For a more “under-the-hood” approach, Linux stores detailed information for every running process in the /proc directory.

You can check the status file for the process:

Bash

grep Uid /proc/1698110/status

This command will output the User ID (UID) of the process owner, which you can then map to a username. The ps command does this for you automatically and is much more straightforward.

Leave a Reply

error: Content is protected !!