Hi, I've created the below 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);

        while ((pid = waitpid(pid, &status, 0))) {
                if (pid < 0)
                else if (WEXITSTATUS(status) > 3)
                        printf("exit status %d hgher than 3\n", WEXITSTATUS(status));
        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?