M
Mike
Hello everyone,
thanks for everyone's comments on my code yesterday. it's been really
helpful and i've learned a lot.
i've been doing some more tests with child processes, this time using exec
with fork.
i am puzzled by this code:
/* a.c, gets compiled to executable a */
main()
{
int i; /* integer */
printf("enter an integer");
scanf("%d", &i);
printf("you entered %d", i);
}
/* b.c */
main()
{
if(!fork())
{
close(0);
execl("./a", 0);
}
}
The terminal output of program b is:
enter an integeryou entered -1209056688
without ever pausing to actually ask the user for input. what gives?
does it have something to do with the two processes sharing file
descriptors for stdin? thanks in advance for the help.
thanks for everyone's comments on my code yesterday. it's been really
helpful and i've learned a lot.
i've been doing some more tests with child processes, this time using exec
with fork.
i am puzzled by this code:
/* a.c, gets compiled to executable a */
main()
{
int i; /* integer */
printf("enter an integer");
scanf("%d", &i);
printf("you entered %d", i);
}
/* b.c */
main()
{
if(!fork())
{
close(0);
execl("./a", 0);
}
}
The terminal output of program b is:
enter an integeryou entered -1209056688
without ever pausing to actually ask the user for input. what gives?
does it have something to do with the two processes sharing file
descriptors for stdin? thanks in advance for the help.