为什么 CPU 时间在其他线程中不同

Why the CPU time is different in other threads

我 运行 top -H -p 为一个进程提供了几个带有 LWP 的线程。 但是,当我首先对 PID 最小的结果进行排序时,我注意到第一个线程中的时间是恒定的,但其他线程的时间在变化。为什么 TIME+ 不一样?

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 16989 root 20 0 106m 28m 2448 S 0.0 0.2 0:22.31 glusterfs 16990 root 20 0 106m 28m 2448 S 0.0 0.2 0:00.00 glusterfs 16992 root 20 0 106m 28m 2448 S 0.0 0.2 0:00.00 glusterfs 16993 root 20 0 106m 28m 2448 S 0.0 0.2 0:00.00 glusterfs 16997 root 20 0 106m 28m 2448 S 0.0 0.2 0:11.71 glusterfs 17010 root 20 0 106m 28m 2448 S 0.0 0.2 0:21.07 glusterfs 17061 root 20 0 106m 28m 2448 S 0.0 0.2 0:00.00 glusterfs

Why TIME+ is different?

因为不同的线程正在执行不同百分比的工作。这可能有多种原因1,但最有可能的是应用程序 (glusterfs) 没有尝试在工作线程之间平均分配工作。

不用担心。如果工作级别(参见 %CPU)可以忽略不计,哪个线程执行工作并不重要。


1 - 如果有人有时间和兴趣,他们可以查看 glusterfs 的源代码以尝试理解其行为。但是,我认为这种努力是没有必要的。

因为时间列是指一个进程消耗的时间,所以当一个进程时间没有改变时,可能意味着这个进程正在“休眠”或者只是在等待另一个进程完成,但可能有还有很多原因。

http://linux.about.com/od/commands/l/blcmdl1_top.htm

TIME:

Total CPU time the task has used since it started. If cumulative mode is on, this also includes the CPU time used by the process's children which have died. You can set cumulative mode with the S command line option or toggle it with the interactive command S. The header line will then be changed to CTIME.