Categories
How To

Linux list processes by user names (EUID and RUID)

I am a new Linux system user. I want to list processes by user names on Linux. How can I show all the processes by a specific username using Linux command line options?

Introduction – A Linux process is nothing but running instance of a program. For example, when you start Firefox to browse Internet, you can create a new process. In Linux, each process is given a unique number called as a process identification (PID). Linux kernel makes sure that each process gets a unique PID. /sbin/init or /lib/systemd/systemd on modern Linux distros always has a PID of 1 because it is eternally the first process on the Linux based system. The ps command used to list the currently running processes and their PIDs on Linux.

Linux list processes by user names

The procedure to view process created by the specific user in Linux is as follows:

  1. Open the terminal window or app
  2. To see only the processes owned by a specific user on Linux run: ps -u {USERNAME}
  3. Search for a Linux process by name run: pgrep -u {USERNAME} {processName}
  4. Another option to list processes by name is to run either top -U {userName} or htop -u {userName} commands

Let us see examples in details to show all processes for a specific user on Linux.

How to see process created by a specific user in Linux

See all process crated by user named tom:
ps -u tom
OR
ps -U tom
EUID is the Effective User ID. The effective user ID describes the user whose file access permissions are used by the process. RUID is the Real User ID. The real user ID identifies the user who created the process. So:

  • -u tom : Show all processes by RUID
  • -U tom : Display all processes by EUID

You can get a list of every process running as vivek (real [RUID] & effective ID [EUID]) in user format:
ps -U vivek -u vivek
ps -U vivek -u vivek u

see all process run by, qemu and postfix users

ps -U qemu -u qemu
ps -U postfix -u postfix
ps -U postfix -u postfix u

How to show all processes for a specific user using top/htop

The syntax is pretty simple to see all processes created by a user named vivek:
top -U vivek

Linux list processes by user name using top command

My favorite command to check what user is running a process:
htop -u vivek

Linux show all processes created and used by a user named ‘vivek’ using htop

How to display user ID associated with a process

Another option is to use the combination of ps command and grep command/egrep command:
sudo ps -ef | grep {userName}
sudo ps -efl | grep {userName}
sudo ps -efl | grep vivek
sudo ps -ef | grep nginx
sudo ps -efl | grep 'www-data'

The www-data user ID associated with a Linux process named lighttpd, nginx, and php-fpm.

To confirm user IDs run the cat command/egrep command/grep command or /etc/passwd as follows:
cat /etc/passwd
grep 'www-data' /etc/passwd

You can print process tree of user named www-data too, run the pstree command:
pstree [options] {userName}
pstree www-data
pstree -l -a -p -s vivek
pstree -laps www-dat

Where,

  • -l : Long format
  • -a : Show command line args
  • -p : Display Linux PIDs
  • -s : See parents of the selected process

The pgrep command

The pgrep command can look up processes based on usernames. The syntax is:
### Only match processes whose Linux effective user ID (euid) is listed ###
pgrep -u euid

Only match processes whose effective user ID (uid) is listed

pgrep -U uid
pgrep -l -u vivek
pgrep -l -U www-data