I want to see list of process created by specific user or group of user in Linux
Can I do it using ps command or is there any other command to achieve this?
3 Answers
To view only the processes owned by a specific user, use the following command:
top -U [username]
Replace the [username] with the required username
If you want to use ps then
ps -u [username]
OR
ps -ef | grep <username>
OR
ps -efl | grep <username>
for the extended listing
Check out the man ps page for options
Another alternative is to use pstree wchich prints the process tree of the user
pstree <username or pid>
-
4All ` ... | grep <username>` solutions don't work if you have two usernames which are longer than N chars. In my case N is 6.guettli– guettli2018-01-19 10:44:17 +00:00Commented Jan 19, 2018 at 10:44
-
1Note: I got an error for
top -U [username], andtop -u [username]worked for me instead. Debian 9. So if anybody else gets an error with the -U form, try the lowercase.Gloweye– Gloweye2018-10-29 09:08:19 +00:00Commented Oct 29, 2018 at 9:08 -
1Note: On FreeBSD it is
ps -U <username>(notice the capitalU)Rahul Bharadwaj– Rahul Bharadwaj2021-04-28 17:13:08 +00:00Commented Apr 28, 2021 at 17:13
try this one
ps -fp $(pgrep -u <username>)
-
How is this better than
ps -u <username>, as mentioned in the existing answer (orps -fu <username>if you want process details)?Stephen Kitt– Stephen Kitt2018-01-23 08:27:39 +00:00Commented Jan 23, 2018 at 8:27 -
ps -u doesn't provide full process details, but ps -fu <username> does. Agree ps -fu is a best solutionuser939407– user9394072018-01-24 10:03:54 +00:00Commented Jan 24, 2018 at 10:03
-
pgrep -u <username> | xargs ps ushows even more process details.ks1322– ks13222022-04-18 19:11:18 +00:00Commented Apr 18, 2022 at 19:11
Note that -e (show all processes) overrides -u and makes it be ignored.
I was passing -e all the time without knowing what the option does, because I usually used ps -ef, and that made -u not work.
So if you want full listing you can keep the -f:
ps -fu USERNAME
Tested on Ubuntu 22.10,
ps -u username. Most commands have a manual page which you can read withman the-command.