Saturday 14 November 2009

Using Linux ps utility to display the command line of a process

Sometimes it is useful to see the full command line of a process when using Linux ps utility. Linux ps utility obeys COLUMNS environment variable or --columns command line option to limit the line size of the output. The default values are normally too small and cause ps to truncate the command line:
[max@truth ~]$ ps -u $USER -fH
UID PID PPID C STIME TTY TIME CMD
max 7421 7385 0 17:04 ? 00:00:00 gnome-session
max 7527 7421 0 17:04 ? 00:00:02 metacity
max 7539 7421 0 17:04 ? 00:00:00 gnome-panel
max 7540 7421 0 17:04 ? 00:00:00 nautilus
max 7541 7421 0 17:04 ? 00:00:00 /usr/libexec/gdu-notification-
max 7543 7421 0 17:04 ? 00:00:00 /usr/bin/seapplet
max 7544 7421 0 17:04 ? 00:00:00 gnome-power-manager
max 7545 7421 0 17:04 ? 00:00:00 gpk-update-icon
max 7550 7421 0 17:04 ? 00:00:00 bluetooth-applet
max 7551 7421 0 17:04 ? 00:00:00 gnome-volume-control-applet
max 7552 7421 0 17:04 ? 00:00:00 nm-applet --sm-disable
max 7559 7421 0 17:04 ? 00:00:00 kerneloops-applet
max 7561 7421 0 17:04 ? 00:00:00 python /usr/share/system-confi
max 8127 1 0 17:25 ? 00:00:01 gcalctool
max 7942 1 0 17:12 ? 00:00:00 /bin/sh /usr/lib64/firefox-3.5.4
max 7954 7942 2 17:12 ? 00:01:34 /usr/lib64/firefox-3.5.4/firef
max 7774 1 0 17:06 ? 00:00:09 emacs
max 7821 7774 0 17:06 pts/0 00:00:00 /bin/bash --noediting -i
max 8600 7821 0 18:15 pts/0 00:00:00 ps -u max -fH
max 7740 1 0 17:05 ? 00:00:00 gnome-screensaver
max 7730 1 2 17:05 ? 00:01:30 rhythmbox
max 7728 1 0 17:05 ? 00:00:00 /usr/libexec/gvfsd-burn --spawne
max 7719 1 0 17:05 ? 00:00:00 /usr/libexec/notification-area-a
max 7717 1 0 17:05 ? 00:00:02 /usr/libexec/clock-applet --oaf-
max 7715 1 0 17:05 ? 00:00:08 /usr/libexec/multiload-applet-2
max 7711 1 0 17:05 ? 00:00:00 /usr/libexec/cpufreq-applet --oa
max 7708 1 0 17:05 ? 00:00:00 /usr/libexec/wnck-applet --oaf-a
max 7698 1 0 17:04 ? 00:00:00 /usr/libexec/gvfs-gphoto2-volume
max 7693 1 0 17:04 ? 00:00:00 /usr/libexec/gvfs-gdu-volume-mon
max 7691 1 0 17:04 ? 00:00:00 /usr/libexec/bonobo-activation-s
max 7687 1 0 17:04 ? 00:00:00 /usr/libexec/gvfsd-trash --spawn
max 7685 1 0 17:04 ? 00:00:00 /usr/libexec/gconf-im-settings-d
max 7572 1 0 17:04 ? 00:00:00 /usr/libexec/im-settings-daemon
max 7569 1 0 17:04 ? 00:00:00 /usr/libexec/notification-daemon
max 7535 1 0 17:04 ? 00:00:00 /usr/libexec//gvfs-fuse-daemon /
max 7529 1 0 17:04 ? 00:00:00 /usr/libexec/gvfsd
max 7519 1 0 17:04 ? 00:00:00 /usr/libexec/gnome-settings-daem
max 7516 1 0 17:04 ? 00:00:00 /usr/libexec/gconfd-2
max 7433 1 0 17:04 ? 00:00:00 dbus-launch --sh-syntax --exit-w
max 7432 1 0 17:04 ? 00:00:00 /bin/dbus-daemon --fork --print-
max 7405 1 0 17:04 ? 00:00:00 /usr/bin/gnome-keyring-daemon --
max 7320 1 1 17:04 ? 00:01:07 /usr/bin/pulseaudio --start --lo
max 7323 7320 0 17:04 ? 00:00:00 /usr/libexec/pulse/gconf-helpe
The maximum command line length of a process can be read from ARG_MAX sysconf variable
[max@truth ~]$ getconf ARG_MAX
2621440
On my system it is 2.5Mb. The first idea that comes to mind to make ps show the full command line is to pass ARG_MAX (+ some constant for other ps output fields) as the line limit to ps.
[max@truth ~]$ ps -u $USER -fH --columns=`getconf ARG_MAX`
Fix bigness error.
UID PID PPID C STIME TTY TIME CMD
Fix bigness error.
max 7421 7385 0 17:04 ? 00:00:00 gnome-session
Fix bigness error.
max 7527 7421 0 17:04 ? 00:00:02 metacity
Fix bigness error.
...
However, ps does not seem to like the columns value. A quick binary search for the maximum of --columns value reveals:
[max@truth ~]$ ps -u $USER -fH --columns=131073
Fix bigness error.
UID PID PPID C STIME TTY TIME CMD
Fix bigness error.
max 7421 7385 0 17:04 ? 00:00:00 gnome-session
Fix bigness error.
max 7527 7421 0 17:04 ? 00:00:02 metacity
Fix bigness error.
...

[max@truth ~]$ ps -u $USER -fH --columns=131072
UID PID PPID C STIME TTY TIME CMD
max 7421 7385 0 17:04 ? 00:00:00 gnome-session
max 7527 7421 0 17:04 ? 00:00:02 metacity
max 7539 7421 0 17:04 ? 00:00:00 gnome-panel
max 7540 7421 0 17:04 ? 00:00:00 nautilus
max 7541 7421 0 17:04 ? 00:00:00 /usr/libexec/gdu-notification-daemon
max 7543 7421 0 17:04 ? 00:00:00 /usr/bin/seapplet
max 7544 7421 0 17:04 ? 00:00:00 gnome-power-manager
max 7545 7421 0 17:04 ? 00:00:00 gpk-update-icon
max 7550 7421 0 17:04 ? 00:00:00 bluetooth-applet
max 7551 7421 0 17:04 ? 00:00:00 gnome-volume-control-applet
max 7552 7421 0 17:04 ? 00:00:00 nm-applet --sm-disable
max 7559 7421 0 17:04 ? 00:00:00 kerneloops-applet
max 7561 7421 0 17:04 ? 00:00:00 python /usr/share/system-config-printer/applet.py
max 8127 1 0 17:25 ? 00:00:01 gcalctool
max 7942 1 0 17:12 ? 00:00:00 /bin/sh /usr/lib64/firefox-3.5.4/run-mozilla.sh /usr/lib64/firefox-3.5.4/firefox
max 7954 7942 2 17:12 ? 00:01:36 /usr/lib64/firefox-3.5.4/firefox
max 7774 1 0 17:06 ? 00:00:10 emacs
max 7821 7774 0 17:06 pts/0 00:00:00 /bin/bash --noediting -i
max 8629 7821 0 18:21 pts/0 00:00:00 ps -u max -fH --columns=131072
max 7740 1 0 17:05 ? 00:00:00 gnome-screensaver
max 7730 1 2 17:05 ? 00:01:37 rhythmbox
max 7728 1 0 17:05 ? 00:00:00 /usr/libexec/gvfsd-burn --spawner :1.7 /org/gtk/gvfs/exec_spaw/1
max 7719 1 0 17:05 ? 00:00:00 /usr/libexec/notification-area-applet --oaf-activate-iid=OAFIID:GNOME_NotificationAreaApplet_Factory --oaf-ior-fd=27
max 7717 1 0 17:05 ? 00:00:02 /usr/libexec/clock-applet --oaf-activate-iid=OAFIID:GNOME_ClockApplet_Factory --oaf-ior-fd=30
max 7715 1 0 17:05 ? 00:00:09 /usr/libexec/multiload-applet-2 --oaf-activate-iid=OAFIID:GNOME_MultiLoadApplet_Factory --oaf-ior-fd=21
max 7711 1 0 17:05 ? 00:00:00 /usr/libexec/cpufreq-applet --oaf-activate-iid=OAFIID:GNOME_CPUFreqApplet_Factory --oaf-ior-fd=24
max 7708 1 0 17:05 ? 00:00:00 /usr/libexec/wnck-applet --oaf-activate-iid=OAFIID:GNOME_Wncklet_Factory --oaf-ior-fd=18
max 7698 1 0 17:04 ? 00:00:00 /usr/libexec/gvfs-gphoto2-volume-monitor
max 7693 1 0 17:04 ? 00:00:00 /usr/libexec/gvfs-gdu-volume-monitor
max 7691 1 0 17:04 ? 00:00:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=19
max 7687 1 0 17:04 ? 00:00:00 /usr/libexec/gvfsd-trash --spawner :1.7 /org/gtk/gvfs/exec_spaw/0
max 7685 1 0 17:04 ? 00:00:00 /usr/libexec/gconf-im-settings-daemon
max 7572 1 0 17:04 ? 00:00:00 /usr/libexec/im-settings-daemon
max 7569 1 0 17:04 ? 00:00:00 /usr/libexec/notification-daemon
max 7535 1 0 17:04 ? 00:00:00 /usr/libexec//gvfs-fuse-daemon /home/max/.gvfs
max 7529 1 0 17:04 ? 00:00:00 /usr/libexec/gvfsd
max 7519 1 0 17:04 ? 00:00:00 /usr/libexec/gnome-settings-daemon
max 7516 1 0 17:04 ? 00:00:00 /usr/libexec/gconfd-2
max 7433 1 0 17:04 ? 00:00:00 dbus-launch --sh-syntax --exit-with-session
max 7432 1 0 17:04 ? 00:00:00 /bin/dbus-daemon --fork --print-pid 9 --print-address 11 --session
max 7405 1 0 17:04 ? 00:00:00 /usr/bin/gnome-keyring-daemon --daemonize --login
max 7320 1 1 17:04 ? 00:01:13 /usr/bin/pulseaudio --start --log-target=syslog
max 7323 7320 0 17:04 ? 00:00:00 /usr/libexec/pulse/gconf-helper
It looks like there is a hardcoded maximum of the line length in Linux Fedora 11 ps utility equal to 128Kb (0x20000 in hex). It would be nice to remove that limit.

p.s.: The lines of this post get truncated when viewed as a web-page using Firefox or Chromium. To view untruncated use an RSS reader, such as Google Reader.

p.p.s.: And yes, I should have updated my Firefox to 3.5.5 which is available on Fedora 11 updates repository now.

2 comments:

  1. A suggestion to the page format:

    Adding one line like

    pre {overflow:auto}

    in blogger's template will give the "pre" tag a scroll bar. The truncated content can be seen in a browser.

    ReplyDelete
  2. I was looking for a mechanism to do just that! Thanks.

    ReplyDelete