2

I want to list all running processes. Each process should be listed with:

  • PID
  • user name
  • group name

Also, the parent/child hierarchy of the processes should be displayed.

1
  • 1
    Not sure why this one has negative votes.
    – bob
    Apr 5, 2019 at 13:11

2 Answers 2

8

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.

2

pstree -p gives you the relationship in tree-from at least, also with pids, but not the other data.

1
  • The simpler format of this approach complements the accepted answer nicely.
    – jmcarter9t
    Feb 23, 2020 at 14:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .