c - wait() system call - does the child ignore this? -
so i've seen following code during revision. know wait() causes parent wait child stop have few questions regarding this.
firstly, when child created, assumption corrected parent continues, changes x value , waits after if-statement?
secondly, when child carries on execution , gets wait(), happens? ignored has nothing wait for?
       #include <sys/types.h>        #include <stdio.h>        #include <unistd.h>        int main() {          int x = 1;           pid_t pid = fork();          if (pid == 0) {              x = x * 2;          } else if (pid > 0) {              x = 3;          }          wait();          // print value of x console          printf("%d\n",x);        }      
you can experiment calling wait() @ begin of child execution. once there no children in process, callling simple ignored.
Comments
Post a Comment