Write a program to create a child process. Parent process will display message child process terminated on termination of child process. (Hint: catch SIGCHLD signal in parent)
# include
# include
# include
# include
# include
void handler(int sig)
{
printf("Iam in handler ...%d\n",sig);
}
main()
{
int status;
pid_t pid;
signal(SIGCHLD,handler);
pid = fork();
printf("Child Process id is : %d\n", pid);
if( pid == 0 )
{
printf("child process id is %d\n",getpid());
exit(0);
}
sleep(3);
pid = wait(&status);
printf("process terminated is %d\n",pid);
}
# include
# include
# include
# include
void handler(int sig)
{
printf("Iam in handler ...%d\n",sig);
}
main()
{
int status;
pid_t pid;
signal(SIGCHLD,handler);
pid = fork();
printf("Child Process id is : %d\n", pid);
if( pid == 0 )
{
printf("child process id is %d\n",getpid());
exit(0);
}
sleep(3);
pid = wait(&status);
printf("process terminated is %d\n",pid);
}
Comments
Post a Comment