Friday, January 9, 2009

Odd "ps" output

While trying to figure out when I started a particular process I noticed that the normal "ps aux" or "ps -eF" is not showing the actual start date, but - depending on how long the task is already running - the year. For example:
[02:09:36 root@lv1-cpq-bl-17 bin]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 1944 656 ? Ss 2008 0:01 init [2]
root 2 0.0 0.0 0 0 ? S 2008 0:00 [migration/0]
root 3 0.0 0.0 0 0 ? SN 2008 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S 2008 0:00 [events/0]
root 5 0.0 0.0 0 0 ? S 2008 0:00 [khelper]
...
root 2851 0.0 3.9 1243532 40740 ? Sl Jan07 1:14 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
root 3521 0.1 4.4 1250100 45828 ? Sl Jan07 2:22 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
root 3629 0.0 4.1 1237900 42880 ? Sl Jan07 0:28 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
root 3799 0.1 5.9 1268268 61260 ? Sl Jan07 3:17 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
root 12274 0.0 0.0 3432 880 pts/4 R+ 03:25 0:00 ps aux

So this varies from the time today when it was started, to a month/day combination all the way to just a year, because the process was started last year.

But when exactly?

Digging into the "man ps" details and using the "trial and error" approach I found out that a custom layout allows to get what I needed:
[root]# ps -e -o user,pid,pcpu,start,stime,time,vsz,rssize,ni,args
USER PID %CPU STARTED STIME TIME VSZ RSS NI COMMAND
root 1 0.0 Jul 01 2008 00:00:01 1944 656 0 init [2]
root 2 0.0 Jul 01 2008 00:00:00 0 0 - [migration/0]
root 3 0.0 Jul 01 2008 00:00:00 0 0 19 [ksoftirqd/0]
root 4 0.0 Jul 01 2008 00:00:00 0 0 -5 [events/0]
root 5 0.0 Jul 01 2008 00:00:00 0 0 -5 [khelper]
...
root 2851 0.0 Jan 07 Jan07 00:01:14 1243532 40740 0 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
root 3521 0.1 Jan 07 Jan07 00:02:22 1250100 45828 0 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
root 3629 0.0 Jan 07 Jan07 00:00:28 1237900 42880 0 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
root 3799 0.1 Jan 07 Jan07 00:03:17 1268268 61260 0 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
root 12275 0.0 03:25:38 03:25 00:00:00 3432 880 0 ps -e -o user,pid,pcpu,start,
stime,time,vsz,rssize,ni,args

The "start" format option resulting in the "STARTED" column above and is showing what I needed. Last thing would be I guess to set the "PS_FORMAT" environment variable if I needed this permanently.

No comments:

Post a Comment