M
Mike
Hi everybody
i'm playing round with more child process code.
this is a program straight from my textbook:
void main(argv, argc)
int argc; char *argv[];
{
int wch, wpar;
if(!fork())
{
printf("child pid %d\n", getpid());
printf("enter child exit status:");
scanf("%d", &wch);
printf("child exiting\n");
_exit(wch);
}
printf("waiting for child to exit\n");
waitpid(-1, &wpar, 0);
printf("child exit status was %d\n", (wpar>>8)&0xff);
}
i'm confused, because when i run it i get
child pid 9567
enter child exit status:waiting for child to exit
and the program just hangs without giving me a chance to enter an exit
status for the child.
can anyone explain? thanks.
i'm playing round with more child process code.
this is a program straight from my textbook:
void main(argv, argc)
int argc; char *argv[];
{
int wch, wpar;
if(!fork())
{
printf("child pid %d\n", getpid());
printf("enter child exit status:");
scanf("%d", &wch);
printf("child exiting\n");
_exit(wch);
}
printf("waiting for child to exit\n");
waitpid(-1, &wpar, 0);
printf("child exit status was %d\n", (wpar>>8)&0xff);
}
i'm confused, because when i run it i get
child pid 9567
enter child exit status:waiting for child to exit
and the program just hangs without giving me a chance to enter an exit
status for the child.
can anyone explain? thanks.