使用CPU终止进程教程

2019-10-29由程序员日记发表于系统教程 浏览45次

ps aux的输出包含以下内容:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ubuntu    1496  9.1  0.0      0     0 pts/0    Z+   19:47   0:30 [python] <defunct>
ubuntu    1501 14.6  0.0      0     0 pts/0    Z+   19:47   0:48 [python] <defunct>
ubuntu    1502 14.8  0.0      0     0 pts/0    Z+   19:47   0:48 [python] <defunct>
ubuntu    1503 15.1  0.0      0     0 pts/0    Z+   19:47   0:49 [python] <defunct>
ubuntu    1504 15.4  0.0      0     0 pts/0    Z+   19:47   0:50 [python] <defunct>
ubuntu    1505 15.8  0.0      0     0 pts/0    Z+   19:47   0:52 [python] <defunct>
ubuntu    1506 16.0  0.0      0     0 pts/0    Z+   19:47   0:53 [python] <defunct>
ubuntu    1507 14.1  0.0      0     0 pts/0    Z+   19:47   0:46 [python] <defunct>
ubuntu    1508 14.3  0.0      0     0 pts/0    Z+   19:47   0:47 [python] <defunct>
ubuntu    1509 14.4  0.0      0     0 pts/0    Z+   19:47   0:47 [python] <defunct>
ubuntu    1510 14.6  0.0      0     0 pts/0    Z+   19:47   0:48 [python] <defunct>
ubuntu    1511 14.9  0.0      0     0 pts/0    Z+   19:47   0:49 [python] <defunct>
ubuntu    1512 10.7  0.0      0     0 pts/0    Z+   19:47   0:35 [python] <defunct>
ubuntu    1513 71.3  0.0      0     0 pts/0    Z+   19:47   3:55 [python] <defunct>

这些是通过多进程产生的一堆进程,这些进程已经完成并且正在等待父进程加入.他们为什么要占用CPU?

如果这只是ps的产物,我如何才能准确了解正在使用多少CPU?

解决方法:

僵尸进程(即“已终止”的进程)不会消耗CPU:它仅由内核保留,以便父进程可以检索有关它的信息(例如返回状态,资源使用情况等).

ps命令指示的CPU使用率与进程运行时(即进程终止并成为僵尸之前)的CPU使用率相对应.