使用execvp声明范围错误

时间:2019-02-07 01:33:48

标签: c shell

我正在编写一个C程序,该程序接收用户在控制台(Linux)中编写的输入,使用接收到的参数创建一个向量,并使用子Shell来执行它们。我在尝试编译时收到所有这些错误/警告。 可能与子Shell的创建有关,但我不确定。 怎么了?

int main(int argc, char *argVector[])
{
    char command[100];
    int status, pid;

    while (1)
    {   
        GetCommand( command );
        if(strcmp(command, "quit\n") == 0) break;
        if ( ( pid = fork() ) < 0 )
        {
            printf("%s\n", "Erro ao realizar fork");
            break;
        }       
        if( pid == 0 )
        {
            makeArgVector(command,argVector);
            if(execvp(argvector[0],argVector) < 0 ) 
            {
                printf("Erro ao executar comando");
                break;
            }
        }else
            wait(&status);
    }
    return 0;
}

一旦我尝试编译程序,该错误/警告就会弹出:

wait(&status) was not declared in this scope.

1 个答案:

答案 0 :(得分:1)

Wait()在wait.h文件中声明。因此我们必须按如下所示包含此标头,以便编译器从标头文件中获取声明。

#include <sys/wait.h>
相关问题