最近在看《Linux下C编程实践》,在讲到进程有关fork和exec函数的时候,报错了。
代码如下:
可以完整编译过
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#define MAX_CMD_LEN 239
char command[MAX_CMD_LEN];
char errorno;
int main()
{
int rtn;
while(1)
{
printf(">");
fgets(command,MAX_CMD_LEN,stdin);
command[strlen(command)-1]=0;
if(fork()==0)
{
execlp(command,command);
perror(command);
exit(errorno);
}
else
{
wait(&rtn);
printf("child process return %d!\n",rtn);
}
}
}
报错:exec.c:12: 警告:隐式声明与内建函数‘strlen’不兼容