Shankar
Shankar

Reputation: 8967

Linux time command - real vs user vs system

I am running a jar file in Linux with time command. Below is the output after execution.

15454.58s real 123464.61s user  6455.55s system

Below is the command executed.

time java -jar -Xmx7168m Batch.jar

But actual time taken to execute the process is 9270 seconds.

Why the actual time(wall clock time) and real time is different?

Can anyone explain this? Its running on multi core machine (32 core).

Upvotes: 3

Views: 1801

Answers (2)

Michael Jaros
Michael Jaros

Reputation: 4681

Maybe this explains the deviation you are experiencing. From the time Wikipedia article:

Because a program may fork children whose CPU times (both user and sys) are added to the values reported by the time command, but on a multicore system these tasks are run in parallel, the total CPU time may be greater than the real time.

Apart from that, your understanding of real time conforms with the definition given in time(7):

Real time is defined as time measured from some fixed point, either from a standard point in the past (see the description of the Epoch and calendar time below), or from some point (e.g., the start) in the life of a process (elapsed time).

See also bash(1) (although its documentation on the time command is not overly comprehensive).

If seconds are exact enough for you, this little wrapper can help:

#!/bin/bash

starttime=$( date +"%s" )
# run your program here
endtime=$( date +"%s" )

duration=$(( endtime-starttime ))
echo "Execution took ${duration} s."

Note: If the system time is changed while your program is running, the results will be incorrect.

Upvotes: 2

Alex
Alex

Reputation: 635

From what I remember, user time is the time it spends in user space, system is the time spend running in kernel space (syscalls, for example), and real is also called the wall clock time (the actual time that you can measure with a stop-watch, for example). Don't know exactly how this is calculated on a SMP system.

Upvotes: 0

Related Questions