- Show what users are running processes on your Linux system
- How to see process created by specific user in Unix/linux
- 3 Answers 3
- You must log in to answer this question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Linux: How to show a list of running processes with PID, user, group, command line, and parent/child hierarchy?
- 2 Answers 2
- The number of processes a user is running using bash
- 9 Answers 9
Show what users are running processes on your Linux system
Typically the w command will show you who is logged in. So do the users and who commands. With the advent of Ubuntu’s unity and the lightdm desktop session manager, these commands don’t tell the whole truth.
Moreover, users don’t need to be logged in to a terminal (or pseudo terminal) in order to run processes or services. If you want a quick and dirty way to see what’s going on, you can use the ps command. Typically you use the “-a -u -f -x” flags with the command ( ps aufx ) if you want the information for all users in easily readable, tree-based, fully formatted output. Pipe it through more or less .
Still, what if you only care about the users, and not all the gory details? What if you just want to know what users are running processes? You can still use the ps command, but filter it through a few pipes: get rid of everything except the first column of output, chop off the header, sort the output, toss out duplicate lines, and there you have it — a simple list of users*
' The above code will give you output like this:
103 avahi colord daemon lp nobody postfix root rtkit statd superman syslog
Now I’ll grant you that there are other ways to do this; you can fine-tune the output of the ps command using optional formatting arguments. The purpose of this example, however, is to illustrate the capabilities of the individual utilities in the chain of pipes, as described in the preceding paragraph.
If you want to customize it even further (and make it even more difficult to read ;-)), you can add a bit of Perl to the end of the command to filter out all system users and only show you the names of regular users (and/or the root user) with active processes:
' ) < chomp; $u = ( getpwnam($_) )[2]; print $_, "\n" if ( ( $u >= 1000 || $u == 0 ) && ( $_ =~ /[[:alpha:]]/ && $_ ne "nobody" ) ) >'
Loosely explained: display “root” who has a UID of 0, display regular users (they will have UID’s of 1000 or higher), don’t display the “nobody” user, and don’t display the effective UID’s of system-level processes running with UID’s that don’t correspond to an entry in the /etc/passwd database. (The formatted Perl code in the above one-liner is provided at the end of this post.) The output will now look something like:
As promised, the formatted Perl code:
Final thoughts: this is terrible. Ubuntu has "broken" the w command (and its relatives). While it’s nice to know that you can still get the info you need by massaging it out of the ps command, this really is a dirty hack.
*There’s a dirty way to “hide” processes from the Linux/Unix process table. There are feasible reasons to do this from time to time, but for the most part it’s only malicious software that does such a thing. The ps command won’t show hidden processes. If you want to guarantee that you can see all processes, take a look at the unhide utility.
- Compile QEMU from source and make a Debian package with CheckInstall
- apt-get “public key is not available: NO_PUBKEY”
- The Linux GPG GUI — PGP Key Setup Howto
- Check The SMART Status Of Your Hard Drives From The Command Line
- Organize Photos By EXIF Date, or “How To Fix Your Shotwell Library With Perl”
- Autostart VMware Virtual Machines at Boot in Linux
- Compiled and Encrypted suid Perl Programs
- Script to Offline and Remove A Disk In Linux
- Lacuna Expanse and Team UNSC
- Animated Gifs on Linux with ffmpeg and imagemagick
- Lunch With Larry Wall
- Red Hat, libvirt, KVM, iptables – What to do when your KVM network stops working
- Load Balancing With Round Robin DNS
- Convert VDI to VMDK (VirtualBox hard disk conversion to VMware format)
- Show what users are running processes on your Linux system
- Encrypt Your Clipboard
- Allow An Unprivileged User To Run A Certain Command With Sudo
- If VNC Shows a Gray Background
- In-Line Search And Replace With Perl Regular Expressions.
- My Ever-Evolving Bash Profile
- Remove An IP Address Ban That Has Been Errantly Blacklisted By Denyhosts
- Monitor Processor Temperature From The Command Line
- Send An Email When Someone Logs In
- Save A Vim Session And Then Resume It
- My .vimrc File
How to see process created by specific user in Unix/linux
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 3
To view only the processes owned by a specific user, use the following command:
Replace the [username] with the required username
If you want to use ps then
Check out the man ps page for options
Another alternative is to use pstree wchich prints the process tree of the user
All ` . | grep
Note: I got an error for top -U [username] , and top -u [username] worked for me instead. Debian 9. So if anybody else gets an error with the -U form, try the lowercase.
How is this better than ps -u
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 :
You must log in to answer this question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Linux: How to show a list of running processes with PID, user, group, command line, and parent/child hierarchy?
Also, the parent/child hierarchy of the processes should be displayed.
2 Answers 2
The magic combination is ps axfo pid,euser,egroup,args
Here is an output example on Ubuntu 16.04:
$ ps axfo pid,euser,egroup,args PID EUSER EGROUP COMMAND 2 root root [kthreadd] 3 root root \_ [ksoftirqd/0] 4 root root \_ [kworker/0:0] 5 root root \_ [kworker/0:0H] 6 root root \_ [kworker/u4:0] 7 root root \_ [rcu_sched] 8 root root \_ [rcu_bh] 9 root root \_ [migration/0] 10 root root \_ [watchdog/0] 11 root root \_ [watchdog/1] 12 root root \_ [migration/1] 13 root root \_ [ksoftirqd/1] 14 root root \_ [kworker/1:0] 15 root root \_ [kworker/1:0H] 16 root root \_ [kdevtmpfs] 17 root root \_ [netns] 18 root root \_ [perf] 19 root root \_ [khungtaskd] 20 root root \_ [writeback] 21 root root \_ [ksmd] 22 root root \_ [khugepaged] 23 root root \_ [crypto] 24 root root \_ [kintegrityd] 25 root root \_ [bioset] 26 root root \_ [kblockd] 27 root root \_ [ata_sff] 28 root root \_ [md] 29 root root \_ [devfreq_wq] 30 root root \_ [kworker/u4:1] 31 root root \_ [kworker/1:1] 32 root root \_ [kworker/0:1] 34 root root \_ [kswapd0] 35 root root \_ [vmstat] 36 root root \_ [fsnotify_mark] 37 root root \_ [ecryptfs-kthrea] 53 root root \_ [kthrotld] 54 root root \_ [acpi_thermal_pm] 55 root root \_ [bioset] 56 root root \_ [bioset] 57 root root \_ [bioset] 58 root root \_ [bioset] 59 root root \_ [bioset] 60 root root \_ [bioset] 61 root root \_ [bioset] 62 root root \_ [bioset] 63 root root \_ [bioset] 64 root root \_ [bioset] 65 root root \_ [bioset] 66 root root \_ [bioset] 67 root root \_ [bioset] 68 root root \_ [bioset] 69 root root \_ [bioset] 70 root root \_ [bioset] 71 root root \_ [bioset] 72 root root \_ [bioset] 73 root root \_ [bioset] 74 root root \_ [bioset] 75 root root \_ [bioset] 76 root root \_ [bioset] 77 root root \_ [bioset] 78 root root \_ [bioset] 79 root root \_ [scsi_eh_0] 80 root root \_ [scsi_tmf_0] 81 root root \_ [scsi_eh_1] 82 root root \_ [scsi_tmf_1] 83 root root \_ [kworker/u4:2] 87 root root \_ [ipv6_addrconf] 88 root root \_ [kworker/1:2] 89 root root \_ [kworker/u4:3] 102 root root \_ [deferwq] 103 root root \_ [charger_manager] 221 root root \_ [kpsmoused] 242 root root \_ [kworker/0:2] 506 root root \_ [mpt_poll_0] 509 root root \_ [mpt/0] 513 root root \_ [scsi_eh_2] 514 root root \_ [scsi_tmf_2] 515 root root \_ [bioset] 517 root root \_ [bioset] 662 root root \_ [raid5wq] 695 root root \_ [bioset] 736 root root \_ [jbd2/sda1-8] 737 root root \_ [ext4-rsv-conver] 802 root root \_ [iscsi_eh] 805 root root \_ [ib_addr] 806 root root \_ [ib_mcast] 807 root root \_ [ib_nl_sa_wq] 808 root root \_ [ib_cm] 809 root root \_ [iw_cm_wq] 810 root root \_ [rdma_cm] 824 root root \_ [kauditd] 1198 root root \_ [iprt-VBoxWQueue] 1778 root root \_ [kworker/1:1H] 1800 root root \_ [kworker/0:1H] 1854 root root \_ [kworker/1:3] 2524 root root \_ [kworker/0:3] 1 root root /sbin/init 794 root root /lib/systemd/systemd-journald 848 root root /sbin/lvmetad -f 872 root root /lib/systemd/systemd-udevd 1815 systemd+ systemd+ /lib/systemd/systemd-timesyncd 1836 root root /usr/sbin/cron -f 1838 daemon daemon /usr/sbin/atd -f 1840 root root /lib/systemd/systemd-logind 1851 root root /usr/sbin/acpid 1853 syslog syslog /usr/sbin/rsyslogd -n 1860 root root /usr/bin/lxcfs /var/lib/lxcfs/ 1865 root root /usr/lib/accountsservice/accounts-daemon 1870 root root /usr/lib/snapd/snapd 1875 message+ message+ /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation 1888 root root /sbin/mdadm --monitor --pid-file /run/mdadm/monitor.pid --daemonise --scan --syslog 1890 root root /usr/lib/policykit-1/polkitd --no-debug 1995 root root /sbin/dhclient -1 -v -pf /run/dhclient.enp0s3.pid -lf /var/lib/dhcp/dhclient.enp0s3.leases -I -df /var/lib/dhcp/dhclient6.enp0s3.lease 2184 root root /sbin/iscsid 2185 root root /sbin/iscsid 2288 root root /usr/sbin/irqbalance --pid=/var/run/irqbalance.pid 2294 root root /usr/sbin/sshd -D 2566 root root \_ sshd: ubuntu [priv] 2602 ubuntu ubuntu \_ sshd: ubuntu@pts/0 2603 ubuntu ubuntu \_ -bash 2618 ubuntu ubuntu \_ ps axfo pid,euser,egroup,args 2301 root root /sbin/agetty --keep-baud 115200 38400 9600 ttyS0 vt220 2305 root root /sbin/agetty --noclear tty1 linux 2568 ubuntu ubuntu /lib/systemd/systemd --user 2570 ubuntu ubuntu \_ (sd-pam)
What I usually do is — I create an alias and drop it in a convenient place such as /etc/profile.d/aliases.sh with the following content:
alias psx='ps axfo pid,euser,egroup,args'
And then I only need to run psx to get the nice, informative output shown above.
The number of processes a user is running using bash
I would like to know how I could get the number of processes for each user that is currently logged in.
9 Answers 9
You could try some variation of this:
ps haux Ou | cut '-d ' -f1 | uniq -c
It gives you the number of processes for each users (being logged in or not). Now you could filter those results using the output of the w command or another way of determining who is logged in.
Nice! Could add a grep ‘ pts\| tty’ before the cut, would cut out any process not tied to a terminal.
ps -u "$(echo $(w -h | cut -d ' ' -f1 | sort -u))" o user= | sort | uniq -c | sort -rn
In order to properly handle usernames that may be longer than eight characters, use users instead of w . The latter truncates usernames.
ps -u "$(echo $(printf '%s\n' $(users) | sort -u))" o user= | sort | uniq -c | sort -rn
Unfortunately w -h truncates user names to 8 characters, it also only lists the logged on users so you don’t get a view of all users, just logon users.
@OliverDungey: The OP asked for users that are currently logged in. If you want processes for all users regardless of whether they’re logged in then you don’t need w — you can just use ps (which can be made to show the long usernames in full). The users command shows logged in users and appears to not truncate the names. My answer could be adapted to use it. I’ll update my answer.