如何告诉“ps”使用所有可用的列?

如何告诉“ps”使用所有可用的列?

要指定列,我可以使用ps's-o选项:

ps -o pid,cmd

我怎样才能ps输出所有可用的列?

答案1

ps是一个非常依赖于系统的命令。所以答案取决于您使用的 Unix 变体。

psLinux 上的 procps-ng 版本 3.3.3 起:

ps -Ao "$(ps L|cut -d' ' -f1 | grep -vx thcount)" | less -S

(由于某种原因thcount出现在已知字段列表中,但不被接受作为-o.的参数nlwp,但可以)。

你会得到很多重复,因为其中许多字段是同一事物的别名(或表达它的不同方式。例如,start一旦你有了 ,你就不再需要lstart)。

让列标题显示字段选择器而不是普通标题(以帮助您优化所需的列):

ps -Ao "$(ps L|sed -n '/thcount/!s/\([^ ]*\).*/\1=\1/p')" | less -S

POSIX 指定的字段有 args、comm、etime、group、nice、pcpu、pgid、pid、ppid、rgroup、ruser、time、tty、user 和 vsz。所以你可以使用

ps -Ao args,comm,etime,group,nice,pcpu,pgid,pid,ppid,rgroup,ruser,time,tty,user,vsz

对于应该适用于所有兼容系统的命令。

答案2

ps axo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,comm,cmd,stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,tt,user,fname,tmout,f,wchan

您自己应该从上面的列表中进行选择。

例如:

mohsen@debian:~$ ps axo pid,ppid,user,cmd
  PID  PPID USER     CMD
    1     0 root     init [2]  
    2     0 root     [kthreadd]
    3     2 root     [ksoftirqd/0]
    4     2 root     [kworker/0:0]
    5     2 root     [kworker/0:0H]
    6     2 root     [kworker/u:0]
    7     2 root     [kworker/u:0H]
    8     2 root     [migration/0]
    9     2 root     [rcu_bh]
   10     2 root     [rcu_sched]
   11     2 root     [watchdog/0]
   12     2 root     [watchdog/1]
   13     2 root     [ksoftirqd/1]
   14     2 root     [migration/1]
   15     2 root     [kworker/1:0]
   16     2 root     [kworker/1:0H]
   17     2 root     [watchdog/2]
   18     2 root     [ksoftirqd/2]
   19     2 root     [migration/2]
   20     2 root     [kworker/2:0]
   21     2 root     [kworker/2:0H]
   22     2 root     [watchdog/3]
   23     2 root     [ksoftirqd/3]
   24     2 root     [migration/3]
   25     2 root     [kworker/3:0]
   26     2 root     [kworker/3:0H]
   27     2 root     [watchdog/4]
   28     2 root     [ksoftirqd/4]
   29     2 root     [migration/4]
   30     2 root     [kworker/4:0]
   31     2 root     [kworker/4:0H]
   32     2 root     [watchdog/5]
   33     2 root     [ksoftirqd/5]
   34     2 root     [migration/5]
   35     2 root     [kworker/5:0]
   36     2 root     [kworker/5:0H]
   37     2 root     [watchdog/6]
   38     2 root     [ksoftirqd/6]
   39     2 root     [migration/6]
   40     2 root     [kworker/6:0]
   41     2 root     [kworker/6:0H]
   42     2 root     [watchdog/7]
   43     2 root     [ksoftirqd/7]
   44     2 root     [migration/7]
   45     2 root     [kworker/7:0]
   46     2 root     [kworker/7:0H]
   47     2 root     [cpuset]
   48     2 root     [khelper]
   49     2 root     [kdevtmpfs]
   50     2 root     [netns]
   51     2 root     [bdi-default]
   52     2 root     [kintegrityd]
   53     2 root     [kblockd]
   54     2 root     [kworker/0:1]
   55     2 root     [kworker/4:1]
   56     2 root     [kworker/2:1]
   57     2 root     [kworker/3:1]
   58     2 root     [khungtaskd]
   59     2 root     [kswapd0]
   60     2 root     [ksmd]
   61     2 root     [khugepaged]
   62     2 root     [fsnotify_mark]
   63     2 root     [crypto]
   67     2 root     [kworker/6:1]
   68     2 root     [kworker/7:1]
   69     2 root     [kworker/1:1]
   70     2 root     [deferwq]
   71     2 root     [kworker/u:1]
   90     2 root     [kworker/5:1]
  192     2 root     [khubd]
  202     2 root     [ata_sff]
  207     2 root     [scsi_eh_0]
  208     2 root     [scsi_eh_1]
  209     2 root     [scsi_eh_2]
  210     2 root     [scsi_eh_3]
  211     2 root     [scsi_eh_4]
  212     2 root     [scsi_eh_5]
  213     2 root     [kworker/u:2]
  214     2 root     [kworker/u:3]
  215     2 root     [kworker/u:4]
  216     2 root     [kworker/u:5]
  217     2 root     [kworker/u:6]
  218     2 root     [kworker/u:7]
  225     2 root     [kworker/0:2]
  232     2 root     [kworker/0:1H]
  260     2 root     [jbd2/sda5-8]
  261     2 root     [ext4-dio-unwrit]
  409     1 root     udevd --daemon
  499     2 root     [kworker/2:1H]
  606     2 root     [kworker/4:1H]
  624     2 root     [kworker/1:1H]
 1019     2 root     [kworker/5:1H]
 1074     2 root     [kworker/3:1H]
 1090     2 root     [kpsmoused]
 1091     2 root     [kworker/1:2]
 1097     2 root     [cfg80211]
 1264     2 root     [hd-audio0]
 1310     2 root     [hd-audio1]
 1559     2 root     [kvm-irqfd-clean]
 1588     2 root     [kworker/2:2]
 1613     1 root     /sbin/brltty -q
 2249     2 root     [jbd2/sda3-8]
 2250     2 root     [ext4-dio-unwrit]
 2623     1 root     /sbin/rpcbind -w
 2653     1 statd    /sbin/rpc.statd
 2659     2 root     [rpciod]
 2661     2 root     [nfsiod]
 2667     1 root     /usr/sbin/rpc.idmapd
 2730     2 root     [flush-8:0]
 3061     1 vnstat   /usr/sbin/vnstatd -d --pidfile /run/vnstat/vnstat.pid
 3126     1 root     /usr/sbin/rsyslogd
 3183     1 root     /usr/sbin/acpi_fakekeyd
 3224     1 daemon   /usr/sbin/atd
 3249     1 root     tclsh /usr/bin/i8kmon -- --daemon --nouserconfig
 3284     1 root     /usr/sbin/acpid
 3331     1 root     /usr/sbin/inetd
 3386     1 nobody   /usr/bin/gdomap -I /var/run/gdomap.pid -p
 3450     2 root     [kauditd]
 3456     1 root     /usr/sbin/lwresd
 3467     2 root     [iprt]
 3473     1 timidity /usr/bin/timidity -Os -iAD
 3531     1 dirmngr  /usr/bin/dirmngr --daemon --sh
 3674     1 privoxy  /usr/sbin/privoxy --pidfile /var/run/privoxy.pid --user pri
 3679     1 root     /usr/sbin/kerneloops
 3702     1 root     /usr/sbin/cron
 3722     1 debian-+ /usr/sbin/tor --defaults-torrc /usr/share/tor/tor-service-d
 3743     1 message+ /usr/bin/dbus-daemon --system
 3793     1 avahi    avahi-daemon: running [debian.local]
 3794  3793 avahi    avahi-daemon: chroot helper
 3816     1 root     /usr/bin/kdm -config /var/run/kdm/kdmrc
 3836  3816 root     /usr/bin/X :0 vt7 -br -nolisten tcp -auth /var/run/xauth/A:
 3840     1 root     /usr/sbin/NetworkManager
 3903     1 root     /usr/lib/policykit-1/polkitd --no-debug
 3914     1 root     /usr/sbin/modem-manager
 3916     1 root     /sbin/wpa_supplicant -u -s -O /var/run/wpa_supplicant
 3921  3816 root     -:0                                    
 3923  3840 root     /sbin/dhclient -d -sf /usr/lib/NetworkManager/nm-dhcp-clien
 3954     1 root     /usr/sbin/nmbd -D
 4024     1 root     /usr/sbin/smbd -D
 4140     1 root     /usr/sbin/minissdpd -i 0.0.0.0
 4153     1 root     /usr/sbin/sshd
 4170     1 root     /sbin/getty 38400 tty1
 4171     1 root     /sbin/getty 38400 tty2
 4172     1 root     /sbin/getty 38400 tty3
 4173     1 root     /sbin/getty 38400 tty4
 4174     1 root     /sbin/getty 38400 tty5
 4175     1 root     /sbin/getty 38400 tty6
 4184  4024 root     /usr/sbin/smbd -D
 4186     1 root     /opt/zebedee/bin/zebedee -f /opt/zebedee/lib/zebedee/config
 4233     1 root     /usr/sbin/console-kit-daemon --no-daemon
 4306  3921 mohsen   gnome-session
 4335  4306 mohsen   [xbrlapi] <defunct>
 4355  4306 mohsen   /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session
 4358     1 mohsen   /usr/bin/dbus-launch --exit-with-session gnome-session
 4362     1 mohsen   /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7
 4365     1 mohsen   /usr/lib/at-spi2-core/at-spi-bus-launcher
 4369  4365 mohsen   /usr/bin/dbus-daemon --config-file=/etc/at-spi2/accessibili
 4372     1 mohsen   /usr/lib/at-spi2-core/at-spi2-registryd --use-gnome-session
 4384  4306 mohsen   /usr/lib/gnome-settings-daemon/gnome-settings-daemon
 4388     1 mohsen   /usr/bin/gnome-keyring-daemon --start --components=ssh
 4397     1 mohsen   /usr/bin/pulseaudio --start
 4399     1 rtkit    /usr/lib/rtkit/rtkit-daemon
 4403     1 mohsen   /usr/lib/gvfs/gvfsd
 4409     1 root     /lib/systemd/systemd-logind
 4417     1 root     /usr/lib/upower/upowerd
 4561     1 mohsen   /usr/lib/gvfs/gvfs-udisks2-volume-monitor
 4565     1 root     /usr/lib/udisks2/udisksd --no-debug
 4605     1 mohsen   /usr/lib/gvfs/gvfs-goa-volume-monitor
 4608     1 mohsen   /usr/lib/gnome-online-accounts/goa-daemon
 4617     1 mohsen   /usr/lib/gvfs/gvfs-afc-volume-monitor
 4622     1 mohsen   /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
 4626     1 mohsen   /usr/lib/gvfs/gvfs-mtp-volume-monitor
 4629  4306 mohsen   /usr/bin/gnome-shell
 4631     1 colord   /usr/lib/colord/colord
 4633     1 root     /usr/lib/packagekit/packagekitd
 4636     1 mohsen   /usr/lib/dconf/dconf-service
 4637  4384 mohsen   syndaemon -i 1.0 -t -K -R
 4642     1 mohsen   /usr/lib/gnome-settings-daemon/gsd-printer
 4649     1 root     /lib/systemd/systemd-localed
 4694     1 mohsen   /usr/lib/gnome-shell/gnome-shell-calendar-server
 4697     1 root     /usr/lib/accountsservice/accounts-daemon
 4703     1 mohsen   /usr/lib/evolution/evolution-source-registry
 4713     1 mohsen   /usr/lib/i386-linux-gnu/gconf/gconfd-2
 4726     1 mohsen   /usr/lib/telepathy/mission-control-5
 4737  4306 mohsen   /usr/lib/evolution/3.8/evolution-alarm-notify
 4742     1 mohsen   /usr/lib/evolution/evolution-calendar-factory
 4766     1 mohsen   /usr/lib/tracker/tracker-store
 4780     1 mohsen   /usr/lib/gvfs/gvfsd-burn --spawner :1.8 /org/gtk/gvfs/exec_
 4817  4629 mohsen   iceweasel
 4915  4629 mohsen   /usr/bin/python /usr/bin/terminator
 4924  4915 mohsen   gnome-pty-helper
 4925  4915 mohsen   /bin/bash
 5014  4925 mohsen   ps axo pid,ppid,user,cmd

相关内容