UNIX time command implementation

I want to know about the time command flow of execution.

I have a doubt in the time calculation for the command execution.

Whether the real time is sum of (time taken to open the unix window + execute the command given infront of the "time" command + close the unix window)
or Just the time taken for executing the same command in the same window.

Please help Me in this regard.

Regards
Sateesh Solapur

The implementation of time may be OS depdendent. But the basic operation is similar on all platforms.

  1. Create the command + arguments as a child process
  2. wait until the child process completes
  3. Call getrusage() for all of the children and display the time consumed - systems are not required to call getrusage(). They may use a feature like the /proc filesystem.

The wall time is how long it took the child (plus its children if any) to complete.
The "sys" component is the sum of kernel time for children.
The "user" component is the sum of user mode execution time for children.

Wall time does not usually add up to sys + user for longer running processes. Why? I/O disk waits, cpu waits, and multiple threads/children all subtract or add to wall time relative to sys + user.