On Fri, Aug 5, 2011 at 8:17 PM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
Hm. I wouldn't have expected it to print the time after the job was foregrounded again.
I sure expect that. After all, the jobs output of the suspended command still mentions the "time" prefix.
This seems to be caused by the handling of the first job suspension when it creates a new process to replace the shell's role in the process handling -- it sets STAT_NOPRINT on the original job (or jobs -- the one(s) that have STAT_TIMED set). The STAT_NOPRINT causes a job to not show up in the output of "jobs" (which just shows the newly-created super job for the whole command), but it also causes the section of the code that would have gotten around to printing out the time info to never get reached.
The attached patch seems to be the right fix for this. It puts a check for STAT_DONE && should_report_time() into the skip_print short-circuit in printjob(). I've tested this with a time-wasting program and some pipelines to see that the output seems correct. For instance, assume that a.out just takes 5 seconds in a cpu-wasting loop:
prompt$ time ./a.out | cat ~/foo/*(^/) | wc
108376 459723 5888382
^Z
[2] + 30000 suspended ./a.out |
30001 done cat ~/foo/*(^/) |
30002 done wc
[1] + 30003 suspended time ./a.out | cat ~/foo/*(^/) | wc
prompt$ %
[1] + 30003 continued time ./a.out | cat ~/foo/*(^/) | wc
./a.out 5.55s user 0.02s system 54% cpu 10.258 total
cat ~/foo/*(^/) 0.00s user 0.01s system 3% cpu 0.239 total
wc 0.21s user 0.00s system 89% cpu 0.241 total
Without the patch, no times would be output at all.
For even more coolness, it would be nice for the shell to keep track of how much elapsed time was spent suspended and either subtract it from the process's wall-clock time output, or output the suspended time in an extra field.
..wayne..