What does the time command do on zsh Mac terminal? And what is the output of "children"?
The time
you use in your question is not a command, but rather a reserved word in zsh. It can be used in two different ways and its output can be customized through the $TIMEFMT
parameter. There is also an external command time on macOS, which produces slightly different output.
Just time
If you use time
by itself (as shown in your question), then your current shell will report time statistics for itself and its children:
-
shell
represents the shell in which you executed yourtime
statement.children
is a summary of all running processes started from (and still owned by) that shell. -
user
andsystem
show the amount of CPU seconds the above processes spent in user mode and kernel mode, respectively. See https://blog.codinghorror.com/understanding-user-and-kernel-mode/ for more info. -
cpu
shows the combined values ofuser
andsystem
, as a percentage of total CPU time.total
shows how long ago the shell or its oldest child process was started (here in minutes:seconds.fraction).
time <command>
More often, time
is added before a command. If you use it that way, then the shell will report time statistics for that command only:
% time sleep 0
sleep 0 0.00s user 0.00s system 43% cpu 0.007 total
%
total
here is the number of seconds it took for the command to complete.
Customizing time
output
time
's output can be customized by setting the $TIMEFMT
parameter. For example, we can add memory usage:
% TIMEFMT+=' max RSS %M'
% time
shell 0.22s user 0.10s system 53% cpu 0.601 total max RSS 6120
children 0.11s user 0.16s system 45% cpu 0.601 total max RSS 3056
% time sleep 0
sleep 0 0.00s user 0.00s system 61% cpu 0.003 total max RSS 580
%
External Command time
The external command time
can be used as follows:
% command time
% command time sleep 0
0.00 real 0.00 user 0.00 sys
% command time -p sleep 0
real 0.00
user 0.00
sys 0.00
% command time -l sleep 0 # Add memory usage
0.00 real 0.00 user 0.00 sys
585728 maximum resident set size
0 average shared memory size
0 average unshared data size
0 average unshared stack size
160 page reclaims
0 page faults
0 swaps
0 block input operations
0 block output operations
0 messages sent
0 messages received
0 signals received
0 voluntary context switches
1 involuntary context switches
2198249 instructions retired
3195521 cycles elapsed
237568 peak memory footprint
%
real
here is the same as total
, above.