title: Calling linux command cmp with C program
body: <p>I'm trying to make a program which is getting 2 pathes for files to main, and calling linux' cmp command in order to compare them.</p>
  
  <p>If they equal, I want to return 2, and if they're different, 1.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  
  int main(int argc, const char* argv[])
  {
  pid_t pid;
  int stat;
  
  //child process
  if ((pid=fork())==0)
  {
      execl("/usr/bin/cmp", "/usr/bin/cmp", "-s",argv[1], argv[2], NULL);
  }
  //parent process
  else
  {
      WEXITSTATUS(stat);
      if(stat==0)
          return 2;
      else if(stat==1) 
          return 1; //never reach here
  }
  printf("%d\n",stat);
  return 0;
  }
  </code></pre>
  
  <p>For some reason if the files are the same, I do succeed in returning 2, but if they're different, it won't go into if(stat==1), but to return 0.
  Why is this happening? I checked that cmp on the files through terminal does truly return 1 if they're different, so why this doesnt work?</p>