Time (Unix)
Encyclopedia
time is a command in the Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 operating systems. It is used to determine the duration of execution of a particular command
Command (computing)
In computing, a command is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. Most commonly a command is a directive to some kind of command line interface, such as a shell....

.

Usage

To use the command, simply precede any command by the word time, such as:

time ls

When the command completes, time will report how long it took to execute the ls
Ls
In computing, ls is a command to list files in Unix and Unix-like operating systems. ls is specified by POSIX and the Single UNIX Specification.- History :An ls utility appeared in the original version of AT&T UNIX...

command in terms of user CPU time
CPU time
CPU time is the amount of time for which a central processing unit was used for processing instructions of a computer program, as opposed to, for example, waiting for input/output operations. The CPU time is often measured in clock ticks or as a percentage of the CPU's capacity...

, system CPU time, and real time. The output format varies between different versions of the command, and some give additional statistics, as in this example:


$ time host wikipedia.org
wikipedia.org has address 207.142.131.235
0.000u 0.000s 0:00.17 0.0% 0+0k 0+0io 0pf+0w
$


time(1) can exist as a standalone program (such as GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 time) or as a shell
Unix shell
A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems...

 builtin (e.g. in tcsh
Tcsh
tcsh is a Unix shell based on and compatible with the C shell . It is essentially the C shell with programmable command line completion, command-line editing, and a few other features.-History:...

 or in zsh).

User Time vs System Time

The term 'user CPU time' can be a bit misleading at first. To be clear, the total CPU time is the combination of the amount of time the CPU(s) spend performing some action for a program and the amount of time the CPU(s) spend performing system call
System call
In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...

s for the kernel on the program's behalf. When a program loops through an array, it is accumulating user CPU time. Conversely, when a program executes a system call
System call
In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...

 such as exec or fork, it is accumulating system CPU time.

Real Time vs CPU Time

The term "real time" in this context refers to elapsed "wall clock" time, like using a stop watch. The total CPU time (user time + sys time) may be more or less than that value. Because a program may spend some time waiting and not executing at all (whether in user mode or system mode) the real time may be greater than the total CPU time. Because a program may fork children whose CPU times (both user and sys) are added to the values reported by the time command, the total CPU time may be greater than the real time.

Method of operation

According to the source code of the GNU implementation of time, most information shown by time is derived from the wait3 system call. On systems that do not have a wait3 call that returns status information, the times system call is used instead.

See also

  • List of Unix programs
  • System time
  • Unix time
    Unix time
    Unix time, or POSIX time, is a system for describing instants in time, defined as the number of seconds elapsed since midnight Coordinated Universal Time of Thursday, January 1, 1970 , not counting leap seconds, which are declared by the International Earth Rotation and Reference Systems Service...

  • Cron
    Cron
    Cron is a time-based job scheduler in Unix-like computer operating systems. Cron enables users to schedule jobs to run periodically at certain times or dates...

    process for scheduling jobs to run at a particular time.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK