当前位置: 技术问答>linux和unix
为什么无法编译,在线等待
来源: 互联网 发布时间:2015-07-20
本文导语: 红帽linux 8.0,源程序如下 #include #include main() { pid_t pid; pid=fork(); if(!pid) printf("I'm the childn"); else if(pid>0) printf("I'm the parentn"); else print("Fork fail!n"); } 编译: gcc example.c -o example ...
红帽linux 8.0,源程序如下
#include
#include
main()
{
pid_t pid;
pid=fork();
if(!pid)
printf("I'm the childn");
else if(pid>0)
printf("I'm the parentn");
else
print("Fork fail!n");
}
编译: gcc example.c -o example
提示: In function `main':
`pid_t' undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
parse error before "pid"
`pid' undeclared (first use in this function)
pid_t 明明是在unistd.h中有定义,为什么啊
#include
#include
main()
{
pid_t pid;
pid=fork();
if(!pid)
printf("I'm the childn");
else if(pid>0)
printf("I'm the parentn");
else
print("Fork fail!n");
}
编译: gcc example.c -o example
提示: In function `main':
`pid_t' undeclared (first use in this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
parse error before "pid"
`pid' undeclared (first use in this function)
pid_t 明明是在unistd.h中有定义,为什么啊
|
定义在
#include
//-------------
#include
#include
#include
main()
{
pid_t pid;
pid=fork();
if(!pid)
printf("I'm the childn");
else if(pid>0)
printf("I'm the parentn");
else
printf("Fork fail!n");
}
#include
//-------------
#include
#include
#include
main()
{
pid_t pid;
pid=fork();
if(!pid)
printf("I'm the childn");
else if(pid>0)
printf("I'm the parentn");
else
printf("Fork fail!n");
}
|
UP
|
you need to include head file listed in "man fork"