title: Interprocess communication sending structure via pipe
body: <p>I have to show the elapsed time to run a command using pipes, so I use the gettimeofday function and pass the pointer through the pipe, but when I'm reading it in the father process I get a different result than expected. I'm supossed to get 1604626608037896 but instead I have this 94762421350317.
  This is my code:</p>
  <pre><code>    if (pipe(p) &lt; 0)
          exit(1);
      pid=fork();
      if (pid == -1){
          printf(&quot;can't fork, error occured\n&quot;);
          exit(EXIT_FAILURE);
      }else if (pid == 0){
          //This is the child I get the time 
          gettimeofday(&amp;current,NULL);
          //I write it in the pipe, if I print the time here i get the result I want
          write(p[1], &amp;current, sizeof(current));
          close(p[1]);
          //then I execute the command
      }else{
          //this is the parent
          if (waitpid(pid, &amp;status, 0) &gt; 0){
              close(p[1]);
              struct timeval inicio;
              //Here is the problem I think, once I tried to read it I get a random number
              read(p[0], &amp;inicio, sizeof(inicio));
              printf(&quot;: %ld,%ld\n&quot;, inicio.tv_sec,inicio.tv_usec); 
              
          }else{
              printf(&quot;waitpid() failed\n&quot;);
          }
          exit(0);
      }
  </code></pre>