title: Obtain this exit status of a child process and from the parent process and print it in the parent.
body: <p>and I was exploring the processes flow in c. I want to update the following program in a way that, the child terminates with an exit status (such as 10). Obtain this exit status from the parent process and print it in the parent. I have tried the following way, but the status am getting from the parent is wrong. Where i went wrong? Please help me on it guys. Thanks in advance. </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;unistd.h&gt;
  #include&lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  
  int main()
  {
      int pid;
      int ppid;
      int status;
      pid=vfork();
      pid_t return_pid = waitpid(pid, &amp;status, WNOHANG);
      //printf("%d\n", pid); --&gt; value = 0
  
      if (pid &lt; 0) {
          printf("\n Error ");
          exit(1);
      } else if (pid==0) {
          printf("\n Hello I am the child process\n");
          printf("\n My pid is:  %d\n", getpid());
          printf("\n My parent pid is:  %d\n", getppid());
          printf("\n My return_pid is:  %d\n", return_pid);
          printf("_______________________________________\n");
          int es = WEXITSTATUS(status);
          printf ("\n Child exit status:  %d\n", es);
          status = es;
          exit(0);
      } else {
          printf("The child has terminated!\n");
          printf("_______________________________________\n");
          printf("\n Hello I am the parent process\n");
          printf("\n My actual pid is %d\n" , getpid());
          printf("\n My parent pid is:  %d\n", getppid());
          printf("\n My return_pid is:  %d\n", return_pid);
          printf("_______________________________________\n");
          printf ("\n Child's Exit staus from parent:  %d\n", status);
          exit(1);
      }
  }
  </code></pre>