Write a program to create a child process. Parent process will display three messages. First message will displayed before creation of child process. Second message will displayed only if child process is alive. Last message will displayed after completion of child process.
#include
#include
main(int argc,char *argv[])
{
int pid,w,status;
printf("parent process before the child process created \n");
pid=fork();
if(pid==0)
{
printf("Parent process during creating the child process \n");
}
sleep(3);
w=wait(&status);
printf(" parent process after the executing child process \n");
}
/*
sai@sai-VirtualBox:~/Desktop$ cc -o p4 p4.c
p4.c: In function main:
p4.c:8:2: warning: incompatible implicit declaration of built-in function printf [enabled by default]
sai@sai-VirtualBox:~/Desktop$ ./p4
parent process before the child process created
Parent process during creating the child process
parent process after the executing child process
parent process after the executing child process
*/
#include
main(int argc,char *argv[])
{
int pid,w,status;
printf("parent process before the child process created \n");
pid=fork();
if(pid==0)
{
printf("Parent process during creating the child process \n");
}
sleep(3);
w=wait(&status);
printf(" parent process after the executing child process \n");
}
/*
sai@sai-VirtualBox:~/Desktop$ cc -o p4 p4.c
p4.c: In function main:
p4.c:8:2: warning: incompatible implicit declaration of built-in function printf [enabled by default]
sai@sai-VirtualBox:~/Desktop$ ./p4
parent process before the child process created
Parent process during creating the child process
parent process after the executing child process
parent process after the executing child process
*/
Comments
Post a Comment