[comp.unix.questions] user vs. system time from "times" function call

cpcahil@virtech.uucp (Conor P. Cahill) (07/05/90)

In article <49785@iuvax.cs.indiana.edu> llin@silver.ucs.indiana.edu (Luen Tor Andrew LIN) writes:
>i used the "times" unix call to compare execution of some routines. i
>was confused by the meanings of "user time" and "system time" from the
>times man page. could someone give me a hint on what they refer to, what
>they differ and what factors affect their values? any piece of
>information will be appreciated.

The differences are based upon what mode the system is in when the
cpu is being used.  If it is in "kernel" or "system" mode, the time 
is accumulated to the system time counter, while user mode goes to 
the user time counter.

User mode is defined as executing instructions within your program itself 
while kernel mode is executing instructions within the kernel because of
a request from your program.

For example, the code:

	for(i=0; i<10000; i++)
	{
		y = y+1;
	}

is all executed by a program in "user mode" because it contains no system
calls.  The code:

	for(i=0; i < 10000; i++)
	{
		y = getpid();
	}

Changes to kernel mode to execute the getpid call.  This will cause the
program to use some system cpu time (although it will be very little
because the getpid() system call is one of the system calls with the 
lowest overhead).

If the system call has to do things (like access the file system) the 
amount of system CPU usage will increase accordingly.  

The differentiation between system and user time is important for 
application/system optimization.

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170