Execution Times
The time a process takes to run on a computer depends on many factors. To begin with, it depends on the speed of the CPU, the registers, the memory and the secondary storage. It also depends on the kind and the number of instructions in the process, how long the process waits in the ready queue, how many times the process is interrupted by the kernel, and how long it waits to go back to the ready queue.With so many factors to consider, there are many possible time measurements that can be made. From all these possibilities, the most important to consider are the following three:
Real Time
The time from when the kernel begins to load it in memory until it is terminated. This corresponds to our classical idea of time keeping.
- User Time
The time that a process spends while running in the CPU in user mode. It is smaller than the real time because it only considers the time when the process is in running state, performing instructions. If a process is interrupted many times, the user time adds up all the times the process was executing statements before these interruptions.
- System Time
The time the kernel takes performing tasks on behalf of the process. This includes the loading time, the time used by the kernel to handle all the interruptions for the process, and the times to do context switching for the process. It does not include any waiting time from the process.
The command time used in a shell provides measurements of these three times. This command is prefixed to the normal program call to be made. For example, the following shows the programs compound and id being timed with the time command:
$ time ./compound 1000 2 7
Table of Compounded Amounts
Created by: ryan
Amount After Period
1000.00 0
1020.00 1
1040.40 2
1061.21 3
1082.43 4
1104.08 5
1126.16 6
1148.69 7
Accumulated Interests:148.69
real 0m0.001s
user 0m0.001s
sys 0m0.000s
$ time ./id
My Process ID: 96145
My Group ID: 96145
My Parent Process ID: 56072
My Parent Group ID: 56072
My Session ID: 56072
My Parent Session ID: 56072
Output of `ps':
PID PGRP PPID PGID SID CMD
56072 56072 56058 56072 56072 /bin/bash --posix
96145 96145 56072 96145 56072 \_ ./id
96146 96145 96145 96145 56072 \_ ps --forest -o pid,pgrp,ppid,pgid,sid,cmd
real 0m0.019s
user 0m0.000s
sys 0m0.011s
If a process is short and it is not often interrupted, the real time may be similar to the addition of the user and system times. Notice that the difference of 5 seconds in these figures on the identify program is due to sleeping time forced on the process. This waiting time is not added neither to the user time, nor to the system time.