I am having error with my code below
#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;
}
I code in GCC(Unix) , and get the following error :
test.c:27:1: error: expected identifier '(' before '}' token
Can someone suggest me any help? Thanks in advance :)
The man page for
waitpid()
states:Anyway, the error might due to the usage of
pid_t
which is defined insys/types.h
.Using
-Wall
to turn on all compiler warnings would have pointed one to the missing prototype ofwaitpid()
.Update: This assumes Linux.