title: Parent trying to read children exit status (or return value), fork and wait
body: <p>I'm confused. Supposedly, basing on man, and many other sources, like this:
  <a href="https://stackoverflow.com/questions/742413/return-code-when-os-kills-your-process/747819#747819">Return code when OS kills your process</a>
  wait(&amp;status) should make it possible for me to get the exit status or return value of a child process?</p>
  
  <p>Those 2 snippets of code, should allow me to see the exit value of it's child, and then print it.
  child process function:</p>
  
  <pre><code>    int childFunction(char in[],char logPath[]){
          FILE *logFile= fopen( logPath, "a" );
          if(logFile==NULL)
          return 1;
          int c=system(in);
          fclose(logFile);
          return(c);
      }
  </code></pre>
  
  <p>and main:</p>
  
  <pre><code>        {...some unimportant code before this}
          result= fork();
          if(result==0){
              exit(childFunction(inLine,logPath));
          }
          else if(result&gt;0){
              int status=0;;
              int c=(int)waitpid(-1,&amp;status,0);
              printf("a:%d b:%d\n",status, WIFEXITED(status));
          else
              return -1;
          i=0;
  </code></pre>
  
  <p>I tried going with wait, sleeping for some time, exiting, returning, and read man page a few times. There either is a basic error in my understanding of this function, or after 4 hours of looking I simply no longer can see it.</p>
  
  <p>SOLVED
  For some reason, which i absolutely do not understand, if you change the <code>return(c)</code> in childFunction to <code>if(c!=)return(1);else return(0)</code> it will work. No idea why.</p>
  
  <p>SOLVED 2
  Okay, now I think I know why. See, it appears that either return call, or wait, reduces status to 8 most significant bits (256). What does that mean? That means, if you send normal int, the first bits are used, while the last 8 are discarded. At the same time, when I specify <code>return (1)</code> compiler automatically "shortens" the int to short int. Solution is to either return a short number, or do it like I did in previous "Solved" comment.</p>