#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/wait.h>

void wait0()
{
    while (wait(NULL) != -1)
        {}
}

void wait1()
{
    while (~wait(NULL));
}

void wait2()
{
    int pid;

    do {
        pid = wait(NULL);
    } while (pid != -1);
}

int main()
{
    int pid;

    pid = fork();
    if (pid == 0) {
        sleep(2);
        printf("finished child\n");
        exit(0);
    }
    wait2();
    printf("finished parent\n");

    return 0;
}
