Код ошибки в C
У меня ошибка с моим кодом ниже
#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;
}
Я кодирую в GCC(Unix) и получаю следующую ошибку:
test.c: 27: 1: ошибка: ожидаемый идентификатор '(' before '}' token
Может кто-нибудь предложить мне какую-нибудь помощь? Заранее спасибо:)
1 ответ
Справочная страница для waitpid()
состояния:
#include <sys/types.h>
#include <sys/wait.h>
Anyway, the error might due to the usage of pid_t
который определен в sys/types.h
,
С помощью -Wall
to turn on all compiler warnings would have pointed one to the missing prototype of waitpid()
,
Update: This assumes Linux.