在psutil模块中,我看到了进程的两种状态,psutil.STATUS_DEAD psutil.STATUS_ZOMBIE。需要了解两者的区别。我能够模拟僵尸进程使用‘杀死-1’和‘杀死-3’命令,但不能模拟死亡进程。
这里有什么想法吗?
发布于 2022-03-10 13:42:36
它们与‘psutil/_comom.py’中定义的不同:
STATUS_ZOMBIE = "zombie"
STATUS_DEAD = "dead"但是如果在5.9.0版中搜索STATUS_DEAD,您可能会发现它们在某种意义上是相同的。
在'psutil/_psbsd.py‘中,STATUS_DEAD不用于任何BSD平台。
# OPENBSD
# According to /usr/include/sys/proc.h SZOMB is unused.
# test_zombie_process() shows that SDEAD is the right
# equivalent. Also it appears there's no equivalent of
# psutil.STATUS_DEAD. SDEAD really means STATUS_ZOMBIE.
# cext.SZOMB: _common.STATUS_ZOMBIE,
cext.SDEAD: _common.STATUS_ZOMBIE,
cext.SZOMB: _common.STATUS_ZOMBIE,在关于Linux的'psutil/_pslinux.py‘中显示:
# See:
# https://github.com/torvalds/linux/blame/master/fs/proc/array.c
# ...and (TASK_* constants):
# https://github.com/torvalds/linux/blob/master/include/linux/sched.h
PROC_STATUSES = {
"R": _common.STATUS_RUNNING,
"S": _common.STATUS_SLEEPING,
"D": _common.STATUS_DISK_SLEEP,
"T": _common.STATUS_STOPPED,
"t": _common.STATUS_TRACING_STOP,
"Z": _common.STATUS_ZOMBIE,
"X": _common.STATUS_DEAD,
"x": _common.STATUS_DEAD,
"K": _common.STATUS_WAKE_KILL,
"W": _common.STATUS_WAKING,
"I": _common.STATUS_IDLE,
"P": _common.STATUS_PARKED,
}这些状态对应于linux的任务状态:
// https://github.com/torvalds/linux/blame/master/fs/proc/array.c
static const char * const task_state_array[] = {
/* states in TASK_REPORT: */
"R (running)", /* 0x00 */
"S (sleeping)", /* 0x01 */
"D (disk sleep)", /* 0x02 */
"T (stopped)", /* 0x04 */
"t (tracing stop)", /* 0x08 */
"X (dead)", /* 0x10 */
"Z (zombie)", /* 0x20 */
"P (parked)", /* 0x40 */
/* states beyond TASK_REPORT: */
"I (idle)", /* 0x80 */
};因此,它们在linux中的区别是显而易见的。什么是Linux上的“僵尸进程”?
在psutil中,如果使用p创建一个进程psutil.Popen(),则将其终止。只要父进程没有终止,或者不调用p.wait(),进程就会始终保持“僵尸”状态。
https://stackoverflow.com/questions/68511337
复制相似问题