In Unix, how do I check the CPU usage of a job?
Note: 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:
In Unix, you can see CPU usage on a job that is running in a number of ways, as described below:
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:
myprog with the name of the program you are
running. The following is an output example for users in the
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
bash, since the
time command is not built
into those shells.
You can also use the Unix command
ps. At the Unix
username with your username. You will see
something like the following:
In this example, the "TIME" column shows that the process running Elm has used 22 CPU seconds.
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
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?
Last modified on December 01, 2009.