/* Wait for child termination - wait.c */
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h> // standard symbolic constant & types
#include<sys/types.h> // for datatype
#include<sys/wait.h> // for wait system call
main()
{
int i,pid;
pid = fork();
if(pid < 0)
{
printf("\nProcess creation failure\n"); exit(-1);
}
else if(pid > 0)
{
wait(NULL);
printf ("\nParent starts\nEven Nos:");
for (i=2;i<=10;i+=2)
printf("%3d",i);
printf("\nParent ends\n");
}
else if(pid == 0)
{
printf ("\nChild starts\nOdd Nos:");
for (i=1;i<10;i+=2)
printf ("%3d",i);
printf ("\nChild ends\n");
}
}
output:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h> // standard symbolic constant & types
#include<sys/types.h> // for datatype
#include<sys/wait.h> // for wait system call
main()
{
int i,pid;
pid = fork();
if(pid < 0)
{
printf("\nProcess creation failure\n"); exit(-1);
}
else if(pid > 0)
{
wait(NULL);
printf ("\nParent starts\nEven Nos:");
for (i=2;i<=10;i+=2)
printf("%3d",i);
printf("\nParent ends\n");
}
else if(pid == 0)
{
printf ("\nChild starts\nOdd Nos:");
for (i=1;i<10;i+=2)
printf ("%3d",i);
printf ("\nChild ends\n");
}
}
output:
No comments:
Post a Comment