#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
int main()
{
pid_t pid = fork();
if (pid < 0)
{
perror("fork failed");
exit(1);
}
else if (pid == 0)
{
printf("Child process : PID = %d\n", getpid());
printf("Child process exiting...\n");
exit(8);
}
else
{
int status;
wait(&status);
printf("Parent process : PID = %d\n", getpid());
printf("Child exited with status = %d\n", WEXITSTATUS(status));
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx1bmlzdGQuaD4KI2luY2x1ZGUgPHN5cy90eXBlcy5oPgojaW5jbHVkZSA8c3lzL3dhaXQuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKaW50IG1haW4oKQp7CiAgICBwaWRfdCBwaWQgPSBmb3JrKCk7CgogICAgaWYgKHBpZCA8IDApCiAgICB7CiAgICAgICAgcGVycm9yKCJmb3JrIGZhaWxlZCIpOwogICAgICAgIGV4aXQoMSk7CiAgICB9CiAgICBlbHNlIGlmIChwaWQgPT0gMCkKICAgIHsKICAgICAgICBwcmludGYoIkNoaWxkIHByb2Nlc3MgOiBQSUQgPSAlZFxuIiwgZ2V0cGlkKCkpOwogICAgICAgIHByaW50ZigiQ2hpbGQgcHJvY2VzcyBleGl0aW5nLi4uXG4iKTsKICAgICAgICBleGl0KDgpOyAKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBpbnQgc3RhdHVzOwogICAgICAgIHdhaXQoJnN0YXR1cyk7CgogICAgICAgIHByaW50ZigiUGFyZW50IHByb2Nlc3MgOiBQSUQgPSAlZFxuIiwgZ2V0cGlkKCkpOwogICAgICAgIHByaW50ZigiQ2hpbGQgZXhpdGVkIHdpdGggc3RhdHVzID0gJWRcbiIsIFdFWElUU1RBVFVTKHN0YXR1cykpOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==