/* Program (using fork() and/or exec() commands) where parent and child execute:
d. before terminating, the parent waits for the child to finish its task
*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a;
a=fork();
if(a<0)
{
printf("Child process could not be created");
exit(-1);
}
else if(a==0)
{
printf("in child process id=%d\n",getpid());
}
else
{
wait(NULL);
printf("in parent process id=%d\n",getppid());
}
return 0;
}
OUTPUT SCREEN:
d. before terminating, the parent waits for the child to finish its task
*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a;
a=fork();
if(a<0)
{
printf("Child process could not be created");
exit(-1);
}
else if(a==0)
{
printf("in child process id=%d\n",getpid());
}
else
{
wait(NULL);
printf("in parent process id=%d\n",getppid());
}
return 0;
}
OUTPUT SCREEN:
No comments:
Post a Comment