How to use the S-output-modifier with Unix/Linux command ps?
I am not sure, but it might be that ps is somewhat buggy in this respect. Try this here:
$ ps p 12104 k timePID TTY STAT TIME COMMAND12104 ? Ss 16:17 /usr/sbin/apache2 -k start$ ps p 12104 k time SPID TTY STAT TIME COMMAND12104 ? Ss 143:16 /usr/sbin/apache2 -k start
This is using the BSD options for ps. It works on my machine, however you get an extra header row and extra columns. I would cut them away using tr and cut:
$ ps p 12104 k time S | tail -n 1 | tr -s '[:space:]' | cut -d ' ' -f 4143:39$ ps p 12104 k time | tail -n 1 | tr -s '[:space:]' | cut -d ' ' -f 416:17
On MacOS X (10.7, Lion) the manual page says:
-S
Change the way the process time is calculated by summing all exited children to their parent process.
So, I was able to get output using:
$ ps -S -o time,etime,pid -p 305 TIME ELAPSED PID 0:00.12 01-18:31:07 305$
However, that output was not really any different from when the '-S
' option was omitted.
I tried:
$ ps -S -o time,etime,pid -p 305 TIME ELAPSED PID 0:00.14 01-18:43:59 305$ time dd if=/dev/zero of=/dev/null bs=1m count=100k102400+0 records in102400+0 records out107374182400 bytes transferred in 15.374440 secs (6983941055 bytes/sec)real 0m15.379suser 0m0.056ssys 0m15.034s$ ps -S -o time,etime,pid -p 305 TIME ELAPSED PID 0:00.14 01-18:44:15 305$
As you can see, the 15 seconds of system time spent copying /dev/zero
to /dev/null
did not get included in the summary.
At this stage, the only way of working out what the '-S
' option does, if anything, is to look at the source. You could look for sumrusage
in the FreeBSD version, for example, at FreeBSD.