I am having a problem with wait () and exit () commands in process management in linux.
As far as I learn, the command wait (& val) will change the variable val of the parent program based on the exit state of the child process. That means when i run the command exit (val) the child process will terminate and give exit state 5 but the output of the code is 1281.
Can anyone explain to me why 1281 instead of 5 ?.Thanks for watching and hope you can answer.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
int val = 5;
if(fork())
wait(&val);
else
exit(val);
printf("%d\n", val);
return val;
}