C语言 函数 'wait' 的隐式声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41884685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:35:02 来源:igfitidea点击:
Implicit declaration of function ‘wait’
提问by AyeJay
I am getting a warning > Implicit declaration of function ‘wait' < and when I run the program it works correctly, I would like to understand why I am getting this warning?
我收到警告 > 函数“wait”的隐式声明 < 并且当我运行程序时它可以正常工作,我想了解为什么会收到此警告?
Thanks in advance
提前致谢
Edit: I forgot to add the library included
编辑:我忘了添加包含的库
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
void create (char* program, char** arg_list)
{
/* put your code here */
pid_t childPid;
int status;
if((childPid = fork()) < 0){
printf("Failed to fork() --- exiting...\n");
exit(1);
}
else if (childPid == 0){ // --- inside the child process
if(execvp(program, arg_list) < 0){ // Failed to run the command
printf("*** Failed to exec %s\n", program);
exit(1);
}
}
else{ // --- parent process
while(wait(&status) != childPid)
printf("...\n");
}
}
回答by usr
You are probably missing the headers for wait(2):
您可能缺少以下标题wait(2):
#include <sys/types.h>
#include <sys/wait.h>

