#include<stdio.h> // printf()
#include<stdlib.h> // exit()
#include<sys/types.h> // pid_t
#include<sys/wait.h> // wait()
#include<unistd.h> // fork
int main(int argc, char **argv)
{
pid_t pid;
pid = fork();
if(pid==0)
{
printf("It is the child process and pid is %d\n",getpid());
int i=0;
for(i=0;i<8;i++)
{
printf("%d\n",i);
}
exit(0);
}
else if(pid > 0)
{
printf("It is the parent process and pid is %d\n",getpid());
int status;
wait(&status);
printf("Child is reaped\n");
}
else
{
printf("Error in forking..\n");
exit(EXIT_FAILURE);
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4gLy8gcHJpbnRmKCkKI2luY2x1ZGU8c3RkbGliLmg+IC8vIGV4aXQoKQojaW5jbHVkZTxzeXMvdHlwZXMuaD4gLy8gcGlkX3QKI2luY2x1ZGU8c3lzL3dhaXQuaD4gLy8gd2FpdCgpCiNpbmNsdWRlPHVuaXN0ZC5oPiAvLyBmb3JrCmludCBtYWluKGludCBhcmdjLCBjaGFyICoqYXJndikKewpwaWRfdCBwaWQ7CnBpZCA9IGZvcmsoKTsKaWYocGlkPT0wKQp7CnByaW50ZigiSXQgaXMgdGhlIGNoaWxkIHByb2Nlc3MgYW5kIHBpZCBpcyAlZFxuIixnZXRwaWQoKSk7CmludCBpPTA7CmZvcihpPTA7aTw4O2krKykKewpwcmludGYoIiVkXG4iLGkpOwp9CmV4aXQoMCk7Cn0KZWxzZSBpZihwaWQgPiAwKQp7CnByaW50ZigiSXQgaXMgdGhlIHBhcmVudCBwcm9jZXNzIGFuZCBwaWQgaXMgJWRcbiIsZ2V0cGlkKCkpOwppbnQgc3RhdHVzOwp3YWl0KCZzdGF0dXMpOwpwcmludGYoIkNoaWxkIGlzIHJlYXBlZFxuIik7Cn0KZWxzZQp7CnByaW50ZigiRXJyb3IgaW4gZm9ya2luZy4uXG4iKTsKZXhpdChFWElUX0ZBSUxVUkUpOwp9CnJldHVybiAwOwp9