In: Computer Science
int main() {
int val = 15;
int pid;
if (pid = fork()){
wait(pid);
printf(“This is parent process and val = “);
}
else{
printf(“This is child process and val = “);
val++;
}
printf("%d\n", val);
return val;
}
Output:
This is child process and val = 16
This is parent process and val = 15
Program:
int main() {
int val = 20;
int pid;
if (pid = fork())
{
wait(pid);
printf("This is parent process and val = ");
}
else{
printf("This is child process and val = ");
val+=5;
}
printf("%d\n", val);
return val;
}