模拟系统有僵尸进程后怎么解决
僵尸进程
#include <stdio.h> #include <sys/types.h> int main() { //fork a child process pid_t pid = fork(); if (pid > 0) //parent process { printf("in parent process, sleep for one miniute...zZ... "); sleep(60); printf("after sleeping, and exit! "); } else if (pid == 0) { //child process exit, and to be a zombie process printf("in child process, and exit! "); exit(0); } return 0; }
首先top
zombie代表僵尸进程
演示
创建一个zombie.c, 把最前面的C复制下来 编译 gcc zombie.c -o zombie 会在本地当前目录生成一个zombie的可执行文件 运行它 此时再看top
查询僵尸进程
ps -A -ostat,ppid,pid,cmd |grep -e '^[Zz]'
kill
kill -HUP 3073