How could my code compliled correctly without necessary headers?

Posted by ZhengZhiren on Stack Overflow See other posts from Stack Overflow or by ZhengZhiren
Published on 2010-05-17T09:37:19Z Indexed on 2010/05/17 9:40 UTC
Read the original article Hit count: 170

Filed under:
|

I use the functions fork(),exec()...

But how can this program compiled without including some extra headers(like sys/types.h, sys/wait.h).

I use ubuntu 10.04 with gcc version 4.4.3

#include <stdio.h>
#include <stdlib.h>

int main()
{
 pid_t pid;

 printf("before fork\n");

 pid = fork();

 if(pid == 0)
 {
  /*child*/
  if(execvp("./cpuid", NULL))
  {
   printf("error\n");
   exit(0);
  }
 }
 else
 {
  if(wait(NULL) != -1)
  {
   printf("ok\n");
  }
 }

 return 0;
}

© Stack Overflow or respective owner

Related posts about linux

Related posts about c