As Russ suggested in the 'patch/list sorry/proc-mtime' thread on 9fans here is a modified ps. A -s flag prints process local start time. Not sure about the -r option, maybe two extra options to ps is over kill? Cheers, John Notes: Mon Apr 10 12:31:19 EDT 2006 rsc Thanks. I added the -r option because there is a nice formatting of it. I don't see any nice formatting of -s so I left it out. I don't like having formattings that completely change when passing certain thresholds. It makes them very hard to deal with programatically. Reference: /n/sources/patch/applied/ps-start-run-time Date: Wed Apr 5 16:43:45 CES 2006 Signed-off-by: j.krug@lancaster.ac.uk Reviewed-by: rsc --- /sys/src/cmd/ps.c Wed Apr 5 16:38:59 2006 +++ /sys/src/cmd/ps.c Thu Apr 6 15:11:10 2006 @@ -9,6 +9,8 @@ Biobuf bout; int pflag; int aflag; +int sflag; +int rflag; void main(int argc, char *argv[]) @@ -24,6 +26,12 @@ case 'p': pflag++; break; + case 'r': + rflag++; + break; + case 's': + sflag++; + break; } ARGEND; Binit(&bout, 1, OWRITE); if(chdir("/proc")==-1) @@ -54,9 +62,11 @@ void ps(char *s) { - ulong utime, stime, size; - int argc, basepri, fd, i, n, pri; - char args[256], *argv[16], buf[64], pbuf[8], status[4096]; + ulong utime, stime, size, runtime; + long tn=time(0); + int argc, basepri, fd, i, n, pri, days, hrs, mins, secs; + char args[256], *argv[16], buf[64], pbuf[8], sbuf[32], rbuf[32], status[4096]; + Tm *pstm; sprint(buf, "%s/status", s); fd = open(buf, OREAD); @@ -77,27 +87,54 @@ * 1 user * 2 state * 3 cputime[6] + * 5 runtime * 9 memory * 10 basepri * 11 pri */ utime = strtoul(argv[3], 0, 0)/1000; stime = strtoul(argv[4], 0, 0)/1000; + runtime = strtoul(argv[5], 0, 0)/1000; size = strtoul(argv[9], 0, 0); + if(pflag){ basepri = strtoul(argv[10], 0, 0); pri = strtoul(argv[11], 0, 0); sprint(pbuf, " %2d %2d", basepri, pri); } else pbuf[0] = 0; - Bprint(&bout, "%-10s %8s %4lud:%.2lud %3lud:%.2lud%s %7ludK %-8.8s ", - argv[1], - s, - utime/60, utime%60, - stime/60, stime%60, - pbuf, - size, - argv[2]); + + if(sflag){ + pstm=localtime(tn-runtime); + if(runtime < 86400) + sprint(sbuf, " %02d:%02d:%02d", + pstm->hour, pstm->min, pstm->sec); + else + sprint(sbuf, " %d%02d%02d", + 1900+pstm->year, 1+pstm->mon, pstm->mday); + } else + sbuf[0] = 0; + + if(rflag){ + secs = runtime%60; + mins = (runtime/60)%60; + hrs = (runtime/3600)%24; + days = runtime/86400; + sprint(rbuf, " %3d:%02d:%02d:%02d", + days, hrs, mins, secs); + } else + rbuf[0] = 0; + + Bprint(&bout, "%-10s %8s %4lud:%.2lud %3lud:%.2lud%s %7ludK%s%s %-8.8s ", + argv[1], + s, + utime/60, utime%60, + stime/60, stime%60, + pbuf, + size, + sbuf, + rbuf, + argv[2]); if(aflag == 0){ Noargs: --- /sys/man/1/ps Wed Apr 5 16:39:09 2006 +++ /sys/man/1/ps Wed Apr 5 16:39:07 2006 @@ -4,12 +4,12 @@ .SH SYNOPSIS .B ps [ -.B -pa +.B -pasr ] .PP .B psu [ -.B -pa +.B -pasr ] [ .I user @@ -93,6 +93,20 @@ flag causes .I ps to print the arguments for the process. Newlines in arguments will be translated to spaces for display. +.PP +With the +.B -s +flag, +.I ps +also prints, after the size, the local start time of each process. If less than 24 hours old the format is HH:MM:SS, if older the format is YYYYMMDD. +.PP +With the +.B -r +flag, +.I ps +also prints, after the size (or start time, if +.B -s +was given) the running time of each process as days, hours, minutes, and seconds. .SH FILES .B /proc/*/status .SH SOURCE