zoukankan      html  css  js  c++  java
  • [学习笔记]孤儿进程僵死进程

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include <unistd.h>
    #include<errno.h>
    #include <signal.h>
    
    /*
    
    孤儿进程
    int main(void)
    {
        
        pid_t pid;
            
        pid = fork();
    
        if (-1 == pid)
        {
            perror("fork err");
            return 0;
        }
        if (pid > 0)
        {
            ;
        }
        if (0 == pid)
        {
            sleep(199);
        }
    
        
        
        return 0;
    }
    */
    
    //僵死进程
    //避免方法:创建子进程的时候可以不管子进程,让Linux内核去管
    
    //信号:异步处理事件,是一种机制.
    //言外之意是说:我们的程序在顺序执行的同时能支持异步的调用信号处理函数.
    //站在Linux内核的角度.
    
    int main(void)
    {
        
        pid_t pid;
    
        // 通过信号注册函数, 忽略子进程死信号
        signal(SIGCHLD, SIG_IGN);
    
            
        pid = fork();
    
        if (-1 == pid)
        {
            perror("fork err");
            return 0;
        }
        if (pid > 0)
        {
            sleep(100);
        }
        if (0 == pid)
        {
            ;
        }
    
        
        
        return 0;
    }
  • 相关阅读:
    JUC学习
    java反射学习
    JSON入门学习
    redis
    NoSQ学习
    手写Lockl锁
    MapReduce过程
    scala学习
    idea jetty 配置
    java 基础--理论知识
  • 原文地址:https://www.cnblogs.com/shichuan/p/4428634.html
Copyright © 2011-2022 走看看