In Unix, how do I check the CPU usage of a job?


If you are concerned about slowing the system down, you can use the nice command to lower your program's priority. For more information about the nice command, at the Unix prompt, enter:

 man nice

In Unix, you can see CPU usage on a job that is running in a number of ways, as described below:

The time command

If you want to see a grand total of CPU time for a program when it finishes running, you can use the time command. At the Unix prompt, enter:

 time myprog

Replace myprog with the name of the program you are running. The following is an output example for users in the csh or tcsh shells:

 1.406u 0.042s 0:04.96 29.0% 2+5k 0+1io 0pf+0w

The program myprog used 1.406 seconds of user time, 0.042 seconds of system time, and 4.96 seconds of real time. The sum of the user and system times is the total CPU time of the process. The percentage (29.0%) indicates the percentage of the CPU's time that the process used while it ran. The output will appear in a slightly different format when using sh, ksh, or bash, since the time command is not built into those shells.

The ps command

You can also use the Unix command ps. At the Unix prompt, enter:

 ps -u username

Replace username with your username. You will see something like the following:

 PID TTY TIME COMMAND 10005 ? 3:03 a.out 15852 rb 0:01 -tcsh (tcsh) 24980 rb 0:00 sh -c /usr/local/bin/emacs /usr1/mmouse/snd.18106 24981 rb 0:02 /usr/local/bin/emacs /usr1/mmouse/snd.18106 22311 rf 0:22 elm

In this example, the "TIME" column shows that the process running Elm has used 22 CPU seconds.

The top command

You may also use the top command. At the Unix prompt, enter:


You will see something similar to the following:

 PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND 28000 mmouse 96 4 276K 144K run 292:20 16.80% 16.80% desert.exe 27999 mmouse 96 4 276K 144K run 292:42 16.02% 16.02% denver.exe 19004 goofy 96 4 428K 160K run 357:11 15.63% 15.63% diskr

User mmouse is at the top of the list, and the "TIME" column shows that the program desert.exe has used 292 minutes and 20 seconds of CPU time. This is the most interactive way to see CPU usage.

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document abej in the Knowledge Base.
Last modified on 2017-05-16 11:49:53.

Contact us

For help or to comment, email the UITS Support Center.