3

From the Bash reference manual, times (emphasis mine):

Print out the user and system times used by the shell and its children.

From help times:

Prints the accumulated user and system times for the shell and all of its child processes.

What is "times used by the shell and its children"?

For example, in a bash shell that has been running for several months:

$ times
0m0.152s 0m0.080s
0m15.804s 0m13.296s

How is it possilble that all kinds of times used by the shell and its children is less than 1 min?

  • what does it mean? – Tim Mar 14 '16 at 23:37
  • not the time running the shell process? See " times used by the shell and its children". – Tim Mar 14 '16 at 23:48
  • Then why " times used by the shell and its children"? – Tim Mar 14 '16 at 23:53
  • 1
    because that's not a number that many people are interested in. and for historical reasons, where on some time-sharing systems you could get billed for CPU time used but not for idle time at the shell prompt (and even on modern HPC clusters it's not uncommon to have limits on shared resources like CPU time). so most people are only or primarily interested in CPU time used, not clock time. – cas Mar 15 '16 at 3:04
  • 1
    btw, help times in bash tells you explicitly Prints the accumulated user and system times for the shell and all of its child processes.. User and System times are not real or clock time (time itself can print all three - real time, user time, and system time - see help time). – cas Mar 15 '16 at 3:07
4

From help times:

Prints the accumulated user and system times for the shell and all of its child processes.

You were emphasising for the shell and all of its child processes when you should have been paying more attention to user and system times.

User Time and System Time is not Real (or clock) time, they are the CPU times used in user code and system function calls respectively.

BTW, the time built-in (and the external utility of the same name) can display all three times - Real Time, User Time, and System Time. From help time:

Execute PIPELINE and print a summary of the real time, user CPU time and system CPU time spent executing PIPELINE when it terminates.

Also BTW. the bash built-in time output format is configurable. I like to to use the following so that it only uses one line of my terminal rather than wasting 3 lines:

export TIMEFORMAT=$'\nreal %3lR\tuser %3lU\tsys %3lS'

The GNU version of the external time utility (/usr/bin/time) allows you to configure the output format with the -f or --format option. Other versions may or may not have similar options...don't know, don't care enough to look it up.

|improve this answer|||||
  • Thanks. See the example in my post, there are four times in the output times. Could you point out the meaning of each time? – Tim Mar 15 '16 at 6:51
  • (1) Are the four numbers: user/system times of the shell, and user/system times of all of its processes? Which number is which? (2) When does the shell spend user/system times? For example, when the shell forks a child process, and calls execve() on a command? When the shell is running a builtin command? – Tim Mar 15 '16 at 7:20
  • 1. Don't know for sure, I've never cared enough to use times (and hardly ever need to even use time). If I had to guess, i'd say it's in the order listed in help times - user (1st field) and system (2nd field) times, for the shell itself (1st line) and then all child processes (2nd line). 2. System time is CPU time spent in system calls (i.e. in the kernel), user time is time spent in userland code (your program, and library function calls that aren't just simple wrappers around kernel syscalls). – cas Mar 15 '16 at 7:44
  • (2) most of time, a shell is waiting for our input following its prompt. when does a shell spend user time, and when does it spend system time? – Tim Mar 15 '16 at 7:48
  • The same as any other program - it spends user time when it's doing something in either its own code or in code that it calls from library functions (incl. libreadline and libc). It uses system time when either its own code or library code calls a kernel function. Everything the shell does causes it to use CPU time (usually both system and user time because the kernel provides a lot of functionality to libc and other software and is the ultimate source of access to hardware like disk and network i/o). – cas Mar 15 '16 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.