title: Code after while loop not printing in forked process of my C code
body: <p>C noob here. Code should print &quot;C1: executing ls command&quot; as well as output from executing the <code>ls -la</code> command. But Im not seeing either. The output from the other print statements in and before the loop are working fine though.</p>
  <h1>C Code</h1>
  <pre><code>    pid_t child1_pid = print_if_err(fork(), &quot;fork&quot;);
      if (child1_pid == 0) {
          printf(&quot;\nChild Process 1\n&quot;);
          printf(&quot;Process ID: %d\n&quot;, getpid());
          printf(&quot;Parent Process ID: %d\n&quot;, getppid());
  
          sleep(2);
          int whale = 6;
          char new_whale[50];
          sprintf(new_whale, &quot;%d&quot;, whale);
          setenv(&quot;WHALE&quot;, new_whale, 1);
          printf(&quot;C1: %d\n&quot;, whale);
  
          while(whale &gt; 3) {
              sleep(3);
              whale = whale - 3;
              sprintf(new_whale, &quot;%d&quot;, whale);
              setenv(&quot;WHALE&quot;, new_whale, 1);
              printf(&quot;C1: %d\n&quot;, whale);
          }
  
          print_if_err(chdir(&quot;/&quot;), &quot;chdir&quot;);
          printf(&quot;C1: executing ls command&quot;);
          execl(&quot;ls&quot;, &quot;-l&quot;, &quot;-a&quot;, NULL);
  
          _exit(0);
      }
  </code></pre>