title: Different results of program in different execution environments
body: <p>I am using Ubuntu 18.04. I am currently doing a course on Operating Systems and was just getting used to fork() and exec() calls.</p>
  <p>I am running the following C program</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  int
  main(int argc, char *argv[])
  {
      printf(&quot;hello world (pid:%d)\n&quot;, (int) getpid());
      int rc = fork();
      if (rc &lt; 0) {
          // fork failed; exit
          fprintf(stderr, &quot;fork failed\n&quot;);
          exit(1);
      } else if (rc == 0) {
          // child (new process)
          printf(&quot;hello, I am child (pid:%d)\n&quot;, (int) getpid());
      } else {
          // parent goes down this path (original process)
          printf(&quot;hello, I am parent of %d (pid:%d)\n&quot;,
             rc, (int) getpid());
      }
      return 0;
  }
  </code></pre>
  <p>On running the code in Sublime Text Editor with the build file</p>
  <pre><code>{
  &quot;cmd&quot; : [&quot;gcc $file_name -o ${file_base_name} &amp;&amp; ./${file_base_name}&quot;],
  &quot;selector&quot; : &quot;source.c&quot;,
  &quot;shell&quot;: true,
  &quot;working_dir&quot; : &quot;$file_path&quot;
  }
  </code></pre>
  <p>I get the result</p>
  <pre><code>hello world (pid:16449)
  hello, I am parent of 16450 (pid:16449)
  hello world (pid:16449)
  hello, I am child (pid:16450)
  </code></pre>
  <p>Whereas if I use the terminal and run the same code using gcc,</p>
  <p>I get</p>
  <pre><code>hello world (pid:17531)
  hello, I am parent of 17532 (pid:17531)
  hello, I am child (pid:17532)
  </code></pre>
  <p>Now I know that the latter is the correct whereas the output I get in Sublime is the wrong one. How can the outputs when the compiler I am using remains the same can be different?</p>