Hi John,
There are ways to get what you want, they're just not convenient :)
The default format for -f is something like this:
% ps -p 31258 -o uid_hack,pid,ppid,c,stime,tname,time,cmd
UID PID PPID C STIME TTY TIME CMD
root 31258 31252 0 13:52 pts/4 00:00:00 bash
But if you use the "start" field instead of "stime":
% ps -p 31258 -o uid_hack,pid,ppid,c,start,tname,time,cmd
UID PID PPID C STARTED TTY TIME CMD
root 31258 31252 0 13:52:10 pts/4 00:00:00 bash
Is that what you're looking for?
If that's what Solaris does, perhaps ps should display "start" when
PS_PERSONALITY is set to solaris (or whatever)?
Cheers,
Tony
--
Tony Ernst
On Fri, Sep 08, 2006 at 01:27:38PM -0400, John Hawkinson wrote:
> Hi!
>
> I just spent a while frustrated trying to get the start time of a
> process under Linux, and this is not easily provided by ps (procps
> 3.2.3). Since /proc/ps/stat is really hard for humans to deal with, I
> think it would be good if there were support for this in procps.
>
> Note that under Solaris, seconds are given by default:
>
> [portnoy!jhawk] ~> ps -fp $$
> UID PID PPID C STIME TTY TIME CMD
> jhawk 27922 27921 0 13:07:49 pts/5 0:00 tcsh
>
> What's the best way to procede? As a quick hack I ran
> edited line 837 of pr_stime() in output.c to add :%S to the format
> specifier.
>
> 825 static int pr_stime(char *restrict const outbuf, const proc_t *restrict
> ...
> 837 fmt = "%H:%M"; /* 03:02 23:59 */
> 838 if(tm_yday != proc_time->tm_yday) fmt = "%b%d"; /* Jun06 Aug27 */
> 839 if(tm_year != proc_time->tm_year) fmt = "%Y"; /* 1991 2001 */
> 840 return strftime(outbuf, 42, fmt, proc_time);
>
> But that's clearly not sufficient, and needs header adjustment, etc.
> Would you welcome a patch that did so, or are the columns considered
> too scarce?
>
> Should there be an option of some sort, and if so, how should it
> be structured?
>
> Such details aside, would you accept this patch?
>
> diff -ur x2/procps-3.2.3/ps/output.c procps-3.2.3/ps/output.c
> --- x2/procps-3.2.3/ps/output.c 2004-08-09 20:05:22.000000000 -0400
> +++ procps-3.2.3/ps/output.c 2006-09-08 13:20:59.000000000 -0400
> @@ -834,7 +834,7 @@
> tm_yday = our_time->tm_yday;
> t = time_of_boot + pp->start_time / Hertz;
> proc_time = localtime(&t); /* not reentrant, this corrupts our_time */
> - fmt = "%H:%M"; /* 03:02 23:59 */
> + fmt = "%H:%M\0\0\0"; /* 03:02 23:59 */
> if(tm_yday != proc_time->tm_yday) fmt = "%b%d"; /* Jun06 Aug27 */
> if(tm_year != proc_time->tm_year) fmt = "%Y"; /* 1991 2001 */
> return strftime(outbuf, 42, fmt, proc_time);
>
> This makes it trivial to binary-patch ps to get the desired solution
> if one is in a hurry (by adding ":%S"). It's not a great answer, but
> it is fast and easy and works for me. It avoids the worries of
> formatting the display, etc., etc.
>
> Thanks.
>
> --jhawk@...
> John Hawkinson
> +1 617 797 0250
|