Linux list processes by user names

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 sam:
ps -u sam
OR
ps -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

Linux list processes by user name using top command

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


Linux show all processes created and used by a user named ‘sam’ 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 sam
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 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


  • 27 istifadəçi bunu faydalı hesab edir
Bu cavab sizə kömək etdi?

Uyğun məqalələr

SSH login without password

You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login...

How to remove a Linux user

How do I drop or remove old users account from my Linux server? I can login using the user’s SSH...

How to restrict and except SSH access to specific IPs

Once your IP is public it gets attention from so many bots in the internet that do brute force...

How to lock and unlock user account in linux

With the help of two commands you can lock and unlock the user account in Linux. To Lock the...

Adding a user to a group

Synopsis This article describes how to add a Linux user (account) to a group. Environment...

Powered by WHMCompleteSolution