Code:#include<stdio.h> #include<stdlib.h> main(void) { if(fork()) {//parent process printf("Parent process\n"); printf("par:%d\n",getpid()); } else {//child process printf("Child process\n"); printf("Child :%d Parent:%d\n",getpid(),getppid()); } }
When we use fork() function, a child process is created. In this case what will status of 'program counter' of a child process (when started).
I know that the child process contains the code of else block,but I don't know why it is so.
In the above code, how the contents of the if block belongs to a child process.Code:#include<stdio.h> #include<stdlib.h> main(void) { printf("ID:%d\n",getpid()); if(fork()==0) {//exclusively child is created? printf("par:%d child:%d\n",getppid(),getpid()); } }



LinkBack URL
About LinkBacks


