zoukankan      html  css  js  c++  java
  • Linux Guard Service

    杀死某个子进程

    杀死守护进程的子进程后,改进程会变为僵尸进程

     14087 ?        Ss     0:00 ./test4-1
     14088 ?        S      0:00  \_ ./test4-1
     14089 ?        S      0:00  \_ ./test4-1
     14090 ?        S      0:00  \_ ./test4-1
     14091 ?        S      0:00  \_ ./test4-1
     14092 ?        S      0:00  \_ ./test4-1
     14093 ?        S      0:00  \_ ./test4-1
     14094 ?        S      0:00  \_ ./test4-1
     14095 ?        S      0:00  \_ ./test4-1
     14096 ?        S      0:00  \_ ./test4-1
     14097 ?        S      0:00  \_ ./test4-1
    [root@localhost 04]# kill -9 14090
    [root@localhost 04]# ps -xf
    

    执行后:

     14087 ?        Ss     0:00 ./test4-1
     14088 ?        S      0:00  \_ ./test4-1
     14089 ?        S      0:00  \_ ./test4-1
     14090 ?        Z      0:00  \_ [test4-1] <defunct>
     14091 ?        S      0:00  \_ ./test4-1
     14092 ?        S      0:00  \_ ./test4-1
     14093 ?        S      0:00  \_ ./test4-1
     14094 ?        S      0:00  \_ ./test4-1
     14095 ?        S      0:00  \_ ./test4-1
     14096 ?        S      0:00  \_ ./test4-1
     14097 ?        S      0:00  \_ ./test4-1
    [root@localhost 04]#
    

    杀死父进程

    守护进程的父进程后,僵尸进程释放,正常子进程变为正常进程

    [root@localhost 04]# kill -9 14087
    [root@localhost 04]# ps -xf
    

    僵尸进程消失了

     14088 ?        S      0:00 ./test4-1
     14089 ?        S      0:00 ./test4-1
     14091 ?        S      0:00 ./test4-1
     14092 ?        S      0:00 ./test4-1
     14093 ?        S      0:00 ./test4-1
     14094 ?        S      0:00 ./test4-1
     14095 ?        S      0:00 ./test4-1
     14096 ?        S      0:00 ./test4-1
     14097 ?        S      0:00 ./test4-1
    

    杀死所有进程

    直接使用进程名称

    pkill 进程名
    

    让子进程随父进程一同结束

    在创建进程后使用prctl,监听父进程的DEATHSIG

    for (i = 0; i < 10; i++) {
        sleep(3);
        printf("new fork() process pid = %d 
    ", pid);
        pid = fork();
        if (pid == 0) {
                prctl(PR_SET_PDEATHSIG,SIGKILL);
                break;
    
        }
    }
    

    当父进程死亡后,子进程会自动收到信号并结束,不会产生僵尸进程和孤儿进程

     14508 ?        Ss     0:00 ./test4-2
     14509 ?        S      0:00  \_ ./test4-2
     14510 ?        S      0:00  \_ ./test4-2
     14511 ?        S      0:00  \_ ./test4-2
     14512 ?        S      0:00  \_ ./test4-2
     14513 ?        S      0:00  \_ ./test4-2
     14514 ?        S      0:00  \_ ./test4-2
     14515 ?        S      0:00  \_ ./test4-2
     14516 ?        S      0:00  \_ ./test4-2
     14517 ?        S      0:00  \_ ./test4-2
     14518 ?        S      0:00  \_ ./test4-2
    [root@localhost 04]# kill -9 14508
    [root@localhost 04]# ps -xf
    
      6786 ?        S      0:00 /usr/libexec/gconfd-2
    [root@localhost 04]# 
    [root@localhost 04]# 
    [root@localhost 04]#
  • 相关阅读:
    MySQL 8.0.14版本新功能详解
    Uncaught TypeError: Right-hand side of 'instanceof' is not an object
    程序员快速技术提升之道
    Windows 10 cmd命令符的使用
    数据千万条,备份第一条:VFEmail被擦除所有数据面临关停
    netty-socketio 示例代码
    idea中 在接口中如何直接跳转到该接口的是实现类中?
    perl DBD处理超时问题
    springboot 启动配置文件配置
    Office Word 发布文章到博客园
  • 原文地址:https://www.cnblogs.com/liutianchen/p/8503534.html
Copyright © 2011-2022 走看看