Regular Expressions   «Prev 

Importance of Enclosing Arguments in Quotes and Time Values

Time Values

Historically, UNIX systems have maintained two different time values:
  1. Calendar time. This value counts the number of seconds since the Epoch:
    00:00:00 January 1, 1970, Coordinated Universal Time (UTC). 
    (Older manuals refer to UTC as Greenwich Mean Time.)
    These time values are used to record the time when a file was last modified, for example. The primitive system data type time_t holds these time values.
  2. Process time: This is also called CPU time and measures the central processor resources used by a process. Process time is measured in clock ticks, which have historically been 50, 60, or 100 ticks per second. The primitive system data type clock_t holds these time values. (Will show how to obtain the number of clock ticks per second with the sysconf function later.) When we measure the execution time of a process, we will see that the UNIX System maintains three values for a process:

Clock time
User CPU time
System CPU time

Clock Time

The clock time, sometimes called wall clock time, is the amount of time the process takes to run, and its value depends on the number of other processes being run on the system. Whenever we report the clock time, the measurements are made with no other activities on the system. The user CPU time is the CPU time attributed to user instructions. The system CPU time is the CPU time attributed to the kernel when it executes on behalf of the process. For example, whenever a process executes a system service, such as read or write, the time spent within the kernel performing that system service is charged to the process. The sum of user CPU time and system CPU time is often called the CPU time. It is easy to measure the clock time, user time, and system time of any process: simply execute the time(1) command, with the argument to the time command being the command we want to measure. For example:

$ cd /usr/include
$ time -p grep _POSIX_SOURCE */*.h > /dev/null
real 0m0.81s
user 0m0.11s
sys 0m0.07s

The output format from the time command depends on the shell being used, because some shells do not run /usr/bin/time, but instead have a separate built-in function to measure the time it takes commands to run.