Gistrec

C++ fork()

Nov 21st, 2017
238
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char* argv[]){
  5.     int i, pid;
  6.     printf("I am the parent! my pid = %d\n",getpid());
  7.     for(i=1; i<11; i++){
  8.         pid = fork();
  9.         if(pid !=0)
  10.             wait();
  11.         else{
  12.             printf("I'm a child!!, Child number = %d, my pid = %d\n",i ,getpid());
  13.             exit(0);
  14.         }
  15.     }
  16.     return 0;  
  17. }
Comments
  • User was banned
Add Comment
Please, Sign In to add comment