Open In App

Difference Between User-CPU-Time and System-CPU-Time in UNIX

Last Updated : 23 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Unix systems distinguish between different categories of time to help users understand where their application spent its processing time. They have a time utility that allows a user to see where their application took significant time to process. The syntax of this utility is as follows:            

time <command-to-be-timed>

Its result generally has three categories as follows:

real <time>
user <time>
sys <time>

The following are the types of time metrics used to measure CPU performance:

  1. Real Time: The total elapsed time from start to finish including all delays such as I/O operations, waiting for resources, etc. It may also include time spent waiting for its turn to process or waiting for resources for the successful execution of the program. 
  2. User Time: The amount of time the CPU spends executing user-level code (the application’s code).
  3. System Time: The time spent by the CPU executing system-level code on behalf of the application, such as handling system calls.

Let’s understand user and system CPU time in detail.

User CPU Time

User CPU time is the time taken by the processor to process the code in your application. It is generally termed as running on user space as opposed to being in the kernel space. When you develop your application, you would have written programming constructs such as conditionals, expressions, looping statements, branches, etc. The time spent on the actual code written by the client is measured via user-cpu-time.

User CPU time refers to the amount of CPU time spent by a process or program in user mode, which is the mode in which the application runs.

System CPU Time

System CPU time is the time taken by the process to process kernel code. When an application is programmed, developers need to write to system output, read from system input, and access a local disk resource such as files, databases, etc. These cross-cutting concerns across applications are addressed via system calls that your operating systems provide. The time spent on this execution is generally referred to as system-cpu-time.

Example

#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{

int i=0;
sleep(60);
FILE* fpt;
fpt = fopen(“/home/test/file1.txt”,”w”);

for(int i=0;i<10000000;i++)
{
printf(“”);
fprintf(fpt,”%d”,i);
}
fclose(fpt);
}

The above code first sleeps for a minute, opens a file resource on the disk, and writes the variable “i” to it till the loop terminates and prints nothing to the console. Finally, it closes the file resource opened from the disk.

We can compile this code with:

gcc test.c

This creates a binary ./a.out

Now if we run,

time ./a.out

On UNIX systems it may generate output as seen below. The actual time may vary from time to time based on the program logic and CPU utilization. 

Output:

real 1m0.557s
user 0m0.452s
sys 0m0.084s

How to Find ‘System’ CPU time

You will typically have the ability to obtain the ‘system’ CPU time from system monitoring tools or commands that are provided by the computer system, outlining all of the information on CPU usage. Typical facilities to do this would be through the Task Manager on a Windows PC and through Activity Monitor on a Mac.

Task Manager in Windows

  • Right-click on the taskbar and select “Task Manager.”
  • Under the “Performance” tab.
  • Under the CPU section, information about the system CPU time can be obtained.

Under Activity Monitor in macOS open

  • Open “Finder” and select “Applications.”
  • Open the “Utilities” folder and then launch “Activity Monitor.”
  • Click the tab that says “CPU.”
  • Now the system CPU time will be available with other information about the CPU.

These utilities show real-time information about CPU usage, including system CPU time, which is the system process and service execution time of the operating system. By tracking the system CPU time, you can understand how much processing power the system-level tasks are really eating up from your PC.

How to Simulate High ‘System’ CPU Time

In order to increase the CPU time of the system indicating high CPU usage, simulation can be done in different ways. One typical way of simulating a high system CPU usage is by employing stress testing tools or applications that heavily lay on the CPU. These types of programs have been created so as to put a stress on resources in a computer system which will represent a situation with high consumption.

Tools such as ‘stress’, ‘sysbench’, or ‘prime95’ will induce high CPU usage. All of these packages are run from the terminal and allow control over the intensity and duration of the test. You can run these tools and watch exactly how the system reacts to high CPU usage and its performance under such conditions of stress.

Keep in mind to apply these tools carefully on production systems since they can have a large performance impact. Run these tests on non production or test systems to eliminate the potential for problems which could inadvertently impact critical operations.

Differences Between User-CPU-time and System-CPU-time

User-CPU-time

System-CPU-time

It is the measure of time taken by the application while executing the code written by the user It is the measure of time taken by an application while executing kernel code
In Unix-based systems, it is generally represented as ‘user’ in response to time utility. In Unix-based systems, it is generally represented as ‘sys’ in response to time utility.
The time taken can be analyzed and optimized by the user. Time taken by the system depends on the system calls of the underlying kernel. 
Scope is Limited to the specific process or program Scope can include CPU time used by other processes or the operating system on behalf of the specific process or program
The amount of CPU time spent in user-mode code is called user CPU time. The amount of CPU time spent in kernel-mode code is called system CPU time.
Example: A program spends 10 seconds executing a loop in its own code. Example: A program spends 2 seconds waiting for data to be loaded from disk by the operating system.


Next Article

Similar Reads