zoukankan      html  css  js  c++  java
  • 在WSL中创建僵尸进程失败

    前言:最近想在WSL中试一下僵尸进程的创建,但发现并不能成功,最后在原生Ubuntu上成功。
    编写C语言文件a.c用于创建僵尸进程,内容如下:

    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    int main()
    {
        pid_t pid = fork();
        if(pid<0)
        {
            printf("ERROR
    ");
        }
        else if(pid==0)
        {
            exit(0);
        }
        else
        {
            while(1){}
        }
        return 0;
    }
    

    编译并在后台运行:

    gcc a.c -o test
    ./test &
    

    并通过ps -l查看,S一栏的内容为Z的即为僵尸进程
    但在WSL中经过多次实验均不能成功创建僵尸进程,最后用ubuntu一次成功,效果如下:

    可见产生了僵尸进程,其pid为8906

    Kill掉父进程后僵尸进程消失

    后记:猜想WSL中具体的实现与真正的linux仍存在区别,因此上谷歌查询,发现也有人提过类似的问题:https://unix.stackexchange.com/questions/519463/wsl-different-behavior-for-zombie-processes
    贴一段下面回答者的总结吧:
    Since there is actually very little you can do with a zombie process, and the zombies are not cluttering up the PID number space, it might be a valid choice for WSL to not attempt to fully reproduce the concept of zombie processes at all for commands like ps.
    简单来讲就是不要尝试在WSL上去学习僵尸进程的概念

  • 相关阅读:
    MAC下cocos2dx环境搭建
    eclipse混淆打包出错
    eclipseme升级
    MyEclipse 10 中增加插件
    j2me图片处理大全
    关于svn使用
    NFS相关
    BMP文件格式图解
    UDA1341TS
    OpenOCD初始化脚本(uboot)
  • 原文地址:https://www.cnblogs.com/drperry/p/12688870.html
Copyright © 2011-2022 走看看