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:
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:
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:
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:
Replace 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.
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% diskrUser 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.
Also see:
- In Unix, how should I submit CPU-intensive jobs?
- In Unix, how do I cancel a batch job?
- In Unix, how can I see my remaining processes from former sessions?
- In Unix, how do I kill another login session remotely?
- In Unix, what is the man command, and how do I use it to read manual pages?
Last modified on June 19, 2008.






