Hi, I've created the below code:

Code:
int main(int argc, char *argv[])
{
        int n;
        pid_t pid;
        int status;

        pid = fork();
        if(pid==0) {
                srand(getpid() * getppid());
                n = rand() % 10 + 1;
                printf("childpid %d, parent pid = %d, n = %d\n", getpid(), getppid(), n);
                exit(n);
       }

        while ((pid = waitpid(pid, &status, 0))) {
                if (pid < 0)
                        ;
                else if (WEXITSTATUS(status) > 3)
                        printf("exit status %d hgher than 3\n", WEXITSTATUS(status));
        }
        wait(NULL);
        return 0;
}
The child process returns a random number, what I need is the parent process to fork another process when the child returns a number higher than 3. This must happen recursively until the child process returns a value lesser than 2.
This is part of an assignment, fork is mandatory. Any help on this?

Regards,
Sergi