zoukankan      html  css  js  c++  java
  • Linux练习(wait父进程等待子进程)

    #include <sys/types.h>
    #include <sys/wait.h>
    #include <unistd.h>
    #include <stdio.h>
    
    int main()
    {
            pid_t pid;
            char *m;
            int n;
            pid=fork();
            if(pid==0)
            {
                    m="this is child";
                    n=5;
            }
            else
            {
                    m="this is father";
                    n=3;    
            }
    
            for(;n>0;n--)
            {
    
                    puts(m);
                    sleep(1);
            }
            if(pid!=0)
            {
                pid_t child_pid;
                child_pid=wait(NULL);
                
                printf("child has finished: %d\n",child_pid);
            
            }
            exit(0);
    
    }
  • 相关阅读:
    20200816
    20200815
    20200813
    20200811
    20200810
    20200806
    20200804
    20200803
    20200802
    20200801
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2707378.html
Copyright © 2011-2022 走看看