Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C语言中的错误代码_C_Gcc_Unistd.h - Fatal编程技术网

C语言中的错误代码

C语言中的错误代码,c,gcc,unistd.h,C,Gcc,Unistd.h,我下面的代码有错误 #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { int i, status; pid_t child; child=fork(); if(child == 0){ for(i=0; i<10; i++){ printf("\tChild

我下面的代码有错误

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
        int i, status;
        pid_t child;
        child=fork();
        if(child == 0){
        for(i=0; i<10; i++){
            printf("\tChild PID = %d\n", getpid());
            printf("\tChild PPID = %d\n", getppid());
            sleep(1);
        }
        exit(0);
        }
        else{
        for(i=0; i<10; i++){
            printf("Parent PID = %d\n", getpid());
            printf("Parent PPID = %d\n", getppid());
        }
        }
        waitpid(child, &status, 0);
        return 0;
}
#包括
#包括
#包括
int main()
{
国际一级,地位;
pid_t儿童;
child=fork();
如果(子项==0){

对于(i=0;i,
waitpid()的手册页说明:

#include <sys/types.h>
#include <sys/wait.h>
#包括
#包括
无论如何,该错误可能是由于使用了
sys/types.h
中定义的
pid\t

使用
-Wall
打开所有编译器警告可能会指向缺少的
waitpid()
原型


更新:这假设Linux。

您的示例代码甚至没有31行长,所以很难在第31行出现错误。准确地说:对我有效…检查在这27行之后是否有一些垃圾。请提供test.c逐字记录。在包含
之后,似乎对LWS有效。是的,它是假的。您键入了它,语法错误为过去了。我们到底该如何帮助你呢?无论如何,ftp或scp将文件从你的虚拟机传输到真实的东西。其他一切对你和我们来说都是浪费时间。什么手册页?一些人没有提到
sys/types.h
。我尝试了gcc-Wall test.c,结果是:test.c:在函数“main”中:test.c:8:2:警告:函数“fork”的隐式声明@VladLazarenko:
此页面是Linux手册页项目3.27版的一部分。有关该项目的说明以及报告错误的信息,请访问http://www.kernel.org/doc/man-pages/.
请原谅,假设OP指的是Linux。您可能想查看本地手册页中的
fork()
或扫描声明它的相应头文件以及您正在使用的其他函数(
waitpid()
sleep()
),然后将这些文件包含到源代码中@adadeh@alk手动搜索标题不是吗?好的