📜  waitpid 的示例代码 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:03.038000             🧑  作者: Mango

代码示例1
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main(){
    int pid;
    int status;
    pid =fork();
    if(pid<0){
        printf("Error");
    }
    else if(pid==0){
         // Child Process
         for(int i=0;i<100;i++){
            value-=1;
            printf("%d \n",value);
         }
        exit(EXIT_SUCCESS);
    }
    
   waitpid(pid,&status,0); // WAIT till child gets over
    // Parent process
   for(int i=0;i<100;i++){
            value-=1;
            printf("%d \n",value);
         }
   printingFunction();
    if (WIFSIGNALED(status)){
        printf("Error\n");
    }
    else if (WEXITSTATUS(status)){
        printf("Exited Normally\n");
    }
    return 0;
    
    }
}