Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CPU Utilization high for sleeping processes

I have a process that appears to be deadlocked:

# strace -p 5075
Process 5075 attached - interrupt to quit
futex(0x419cf9d0, FUTEX_WAIT, 5095, NULL

It is sitting on the "futex" system call, and seems to be indefinitely waiting on a lock. The process is shown to be consuming a large amount of CPU when "top" is run:

# top -b -n 1
top - 23:13:18 up 113 days,  4:19,  1 user,  load average: 1.69, 1.74, 1.72
Tasks: 269 total,   1 running, 268 sleeping,   0 stopped,   0 zombie
Cpu(s):  8.1%us,  0.1%sy,  0.0%ni, 91.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  12165696k total,  3810476k used,  8355220k free,    29440k buffers
Swap:  8388600k total,    43312k used,  8345288k free,   879988k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
5075 omdb      18   0 2373m 1.7g  26m S 199.7 14.9 102804:11 java

The process is also shown to be in a "S" - Sleep state, which makes sense if it's waiting on some resource. However, I don't understand why CPU utilization would be close to 200% if the process is in the sleep state. Why does top report such high CPU utilization on a sleeping process? Shouldn't its CPU utilization be zero?

like image 952
blindsnowmobile Avatar asked May 16 '12 23:05

blindsnowmobile


1 Answers

There is no correlation between CPU usage as reported by top and process state. The man page says (emphasis mine):

%CPU -- CPU usage

The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.

So, your process indeed used a huge amount of processor time since the last screen update. It is sleeping, yes, but that's because the currently running process is top itself (which makes sense, since it's currently updating the screen).

like image 114
Frédéric Hamidi Avatar answered Nov 15 '22 15:11

Frédéric Hamidi