Advertisement
Guest User

SHUTGORGE

a guest
Dec 6th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <sys/wait.h>
  5. #include <unistd.h>
  6. void function(int n){
  7.   while(n>0){
  8.     printf("v1 %d\n",getpid());
  9.     pid_t pid = fork();
  10.     if(pid>0){
  11.       waitpid(-1,NULL,0);
  12.       printf("v2 %d\n", getpid());
  13.       exit(EXIT_SUCCESS);
  14.     }
  15.     n--;
  16.   }
  17.   exit(EXIT_SUCCESS);
  18.   }
  19.  
  20. int main(int argc, char *argv[]){
  21.   int n  = atoi(argv[1]);
  22.   if(n>0){
  23.     function(n);
  24.   }
  25.   else{
  26.     printf("Erreur\n");
  27.   }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement