SCRIPT TO CREATE CHILD PROCESS ,PRINT IT AND TERMINATE
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>
int main()
{
pid_t cpid;
system("clear");
switch(cpid=fork())
{
case -1 : perror("error is creating a child process");
exit(0);
case 0 : printf("child created");
printf("child process id:%d \n parent process id:%d",getpid(),getppid());
exit(0);
}
if(wait(0)==cpid)
{
printf("parent process is:%d \nthe owner process is:%d \nchild process idis%d\n",getpid(),getpid(),cpid);
}
return(0);
}
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>
int main()
{
pid_t cpid;
system("clear");
switch(cpid=fork())
{
case -1 : perror("error is creating a child process");
exit(0);
case 0 : printf("child created");
printf("child process id:%d \n parent process id:%d",getpid(),getppid());
exit(0);
}
if(wait(0)==cpid)
{
printf("parent process is:%d \nthe owner process is:%d \nchild process idis%d\n",getpid(),getpid(),cpid);
}
return(0);
}