Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. //PROCESS PROGRAM
  2. //To compile : g++ <filename.cc>
  3. //To Run :./ a.out
  4. #include <sys/types.h>
  5. #include <unistd.h>
  6. #include <sys/wait.h>
  7. #include <stdio.h>
  8.  
  9. void function(int value);
  10. int sum = 0;
  11. int main (void){
  12. int status;
  13. int pid = waitpid ( fork () , &status , 0);
  14. if ( pid > 0 ) { // parent
  15.  
  16. sum++;
  17. }else { // child
  18. function ( fork ());
  19. }
  20. printf( "Sum: %d\n",sum);
  21. return 0 ;
  22. }
  23. void function (int pArg){
  24. int status;
  25. if ( pArg != 0 ){ // CHILD
  26. waitpid(pArg,&status,0);
  27. }
  28. sum++;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement