Yes, you're mis-understanding how waitpid works.
You got the return result test wrong.
Further, you don't explain how child exits your while(true) loop. Does it go round again and make further children of it's own?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(void) {
pid_t p;
p = fork();
if ( p == 0 ) {
printf("This is child %d\n", getpid() );
sleep(10);
printf("Child exiting\n");
exit(0);
} else if ( p > 0 ) {
int status;
printf("This is parent of child %d\n", p );
while ( waitpid(p, &status, WNOHANG) == 0 ) {
printf("Still waiting\n");
sleep(1);
}
if ( WIFEXITED(status) ) {
printf("Child exited normally with status %d\n",WEXITSTATUS(status));
}
}
else {
fprintf(stderr,"Bad fork, try a spoon\n");
}
}