函数“wait”的隐式声明
Implicit declaration of function ‘wait’
我收到一条警告 > 函数“等待”的隐式声明 < 当我 运行 程序正常运行时,我想了解为什么收到此警告?
提前致谢
编辑:我忘了添加包含的库
#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");
}
}
您需要输入:
#include <sys/types.h>
#include <sys/wait.h>
在程序的顶部获取函数的声明。
这显示在 man page
您可能缺少 wait(2)
的 headers:
#include <sys/types.h>
#include <sys/wait.h>
我收到一条警告 > 函数“等待”的隐式声明 < 当我 运行 程序正常运行时,我想了解为什么收到此警告?
提前致谢
编辑:我忘了添加包含的库
#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");
}
}
您需要输入:
#include <sys/types.h>
#include <sys/wait.h>
在程序的顶部获取函数的声明。
这显示在 man page
您可能缺少 wait(2)
的 headers:
#include <sys/types.h>
#include <sys/wait.h>