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:
- Open the terminal window or app
- To see only the processes owned by a specific user on Linux run: ps -u {USERNAME}
- Search for a Linux process by name run: pgrep -u {USERNAME} {processName}
- 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 sam:ps -u sam
ORps -U sam
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 sam (real [RUID] & effective ID [EUID]) in user format:ps -U vivek -u sam
ps -U vivek -u sam u
## see all process run by, sisrv and postfix users ##
ps -U sisrv -u sisrv
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 sam
My favorite command to check what user is running a process:htop -u sam
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 sam
sudo ps -ef | grep nginx
sudo ps -efl | grep 'www-data'
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 sam
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 sam
pgrep -l -U www-data