The above output is wrong.
Main process:
val = 5;
wait(&val); // wait until child finishes
Child process:
val++; // val becomes 6
printf("%d\n", val); // prints 6
return val; // return val*256 back to main process
Main process:
wait(&val); // val becomes 6
val++; // val becomes 1792+1=1793
printf("%d\n", val); // prints 1793
return val;
The above output is right if you add one line in a code !
Program 1:
main()
{
val = 5;
if(fork())
wait(&val);
val=val/256 // if you add this line then the above output is correct
val++;
printf("%d\n", val);
return val;
}
it is due to
#define WEXITSTATUS(status) (((status)>>8) & 0xFF)