Linuc C语言生成僵尸进程

IT影子

关注

阅读 89

2022-08-05


3.c源码

#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
int main()
{
int i;
pid_t pid;
for (i = 0; i < 50; ++i)
{
pid = fork();
switch(pid)
{
case -1:
perror("fork");
exit(-1);
case 0: //child
printf("I am child");
exit(0);
default:
break;
}
}
while (1)
{
sleep(1);
printf("I am parent/n");
}
return 0; //will never reach here
}

2.编译C语言​​​​

[root@node02:/home/sa.haibo.he]$ gcc -o 3 3.c
[root@node02:/home/sa.haibo.he]$ ./3
I am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am childI am parent

I am parent
I am parent
I am parent

3.查看僵尸进程

[root@node02:/root]$ ps -ef | grep defunct | grep -v grep | wc -l
50

版权声明:本文为博主原创文章,未经博主允许不得转载。


精彩评论(0)

0 0 举报