Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PROCESS PROGRAM
- //To compile : g++ <filename.cc>
- //To Run :./ a.out
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <stdio.h>
- void function(int value);
- int sum = 0;
- int main (void){
- int status;
- int pid = waitpid ( fork () , &status , 0);
- if ( pid > 0 ) { // parent
- sum++;
- }else { // child
- function ( fork ());
- }
- printf( "Sum: %d\n",sum);
- return 0 ;
- }
- void function (int pArg){
- int status;
- if ( pArg != 0 ){ // CHILD
- waitpid(pArg,&status,0);
- }
- sum++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement