unsigned int snooze(unsigned int secs)
{
    pid_t pid;
    int status;
    unsigned int i = 1;
    while (i <= secs)
    {
        pid = Fork();
        sleep(1);
        if (pid != 0)
        {
            if (pid = waitpid(-1, &status, 0) > 0)
            {
                if (WIFEXITED(status))
                {
                    printf("Slept for %d of %d secs.\n", i, secs);
                    fflush(stdout);
                    i++;
                }
                else
                {
                    printf(" %d abnormally", pid);
                }
            };
        }
        else
        {
            exit(0);
        }
    }
    exit(0);
}

Views: 177

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.