What specifically are wall-clock-time, user-cpu-time, and system-cpu-time in UNIX?

UnixOperating System

Unix Problem Overview


I can take a guess based on the names, but what specifically are wall-clock-time, user-cpu-time, and system-cpu-time in UNIX?

Is user-cpu time the amount of time spent executing user-code while kernel-cpu time the amount of time spent in the kernel due to the need of privileged operations (like IO to disk)?

What unit of time is this measurement in?

And is wall-clock time really the number of seconds the process has spent on the CPU or is the name just misleading?

Unix Solutions


Solution 1 - Unix

Wall-clock time is the time that a clock on the wall (or a stopwatch in hand) would measure as having elapsed between the start of the process and 'now'.

The user-cpu time and system-cpu time are pretty much as you said - the amount of time spent in user code and the amount of time spent in kernel code.

The units are seconds (and subseconds, which might be microseconds or nanoseconds).

The wall-clock time is not the number of seconds that the process has spent on the CPU; it is the elapsed time, including time spent waiting for its turn on the CPU (while other processes get to run).

Solution 2 - Unix

Wall clock time: time elapsed according to the computer's internal clock, which should match time in the outside world. This has nothing to do with CPU usage; it's given for reference.

User CPU time and system time: exactly what you think. System calls, which include I/O calls such as read, write, etc. are executed by jumping into kernel code and executing that.

If wall clock time < CPU time, then you're executing a program in parallel. If wall clock time > CPU time, you're waiting for disk, network or other devices.

All are measured in seconds, per the SI.

Solution 3 - Unix

time [WHAT-EVER-COMMAND]

real    7m2.444s
user    76m14.607s
sys 2m29.432s

$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                24

real or wall-clock

real 7m2.444s

On a system with 24 core processor, this cmd/process took 7+ mins to complete. That by utilizing the most possible parallelism with all given cores.

user

user 76m14.607s

The cmd/process has utilized this much amount of cpu time. In other words, on machine with single core CPU, the real and user will be nearly equal, so the same command will take ~76 mins to complete.

sys

sys 2m29.432s

This is the time taken by the kernel to execute all the basic/system level operations to run this cmd, including context switching, resource allocation, etc.

> Note: The example assumes that your command utilizes parallelism/threads. > > Detailed man page: https://linux.die.net/man/1/time

Solution 4 - Unix

Wall clock time is exactly what it says, the time elapsed as measured by the clock on your wall (or wristwatch)

User cpu time is the time spent in "user land", that is time spent on non-kernel processes

System cpu time is time spent in the kernel, usually time spent servicing system calls.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn HumphreysView Question on Stackoverflow
Solution 1 - UnixJonathan LefflerView Answer on Stackoverflow
Solution 2 - UnixFred FooView Answer on Stackoverflow
Solution 3 - UnixSankarganesh EswaranView Answer on Stackoverflow
Solution 4 - UnixennuikillerView Answer on Stackoverflow