On Jun 25, 11:36 am, Ravi <ra.ravi....@gmail.com> wrote:
> #include <stdio.h>
> main()
> {
> int pid = fork();
> if(pid==0) {
> printf("1:the child about to become a zombie.pid = %d",getpid());
> } else {
> printf("\n0.0
arent here. pid = %d",getpid());
> getchar(); // inclusion of this line changes the output. why?-----*
> pid=fork();
> if (pid==0) {
> printf("\n2:the child about to become a zombie. pid =
> %d",getpid());
> } else {
> printf("\n0.1
arent here. pid = %d",getpid());
> printf("\n0.2:now look into process table");
> getchar();
> }
> }
>
> }
>
> Can you please explain why exclusion of the *ed statement changes the
> output of the program
Sorry, but no, we can't.
First off, you use a function (fork()) that is not part of the C
language. Likely, you got this function from someplace else (my guess
is a Unix system function), and while /you/ may know what it does, we
don't.
Secondly, even if we did know what fork() does (and a great number of
here probably do), we don't know what the output of your program looks
like, in order to explain why a single call to getchar() would change
it.
My suggestion is that you ask your question (with more details) in a
forum that knows about C programming and the fork() function.