lab4 Process
  • Introduction
  • Knowing about process
    • Checking System Process
    • Process Identification
  • Let's Fork! Process Creation
    • Background of Process Creation
    • fork system call
    • Distinguish Parent and Child Process
    • Exercises
  • Process Execution
    • First exec example
    • Environment Variables
    • exec Family
    • exec Family: execlp
    • exec Family: execle
    • exec Family: execv
    • exec Family: execvp
    • exec Family: execve
    • exec error handling
  • Wait!
    • Problem 1: Without Wait?
    • Sleep
    • Problem 2: Zombies!
    • Wait System Call
    • waitpid
Powered by GitBook
On this page

Was this helpful?

  1. Wait!

Problem 2: Zombies!

The following code simulates a shell that executes ls in each round.

/* Wait/problematic2.c */
#include <stdio.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
    while(1)
    {
        printf("Press Enter to execute ls");
        while(getchar() != '\n');
        if(!fork())
        {
            execl("/bin/ls","ls",NULL);
        }
        else
        {
            sleep(1);
         }
    }
    return 0;
}

The program will run without apparent problems. However, if you look at the system process...

Zombies appear!!

This is the consequence of the mishandling in the parent process- the parent ignores the SIGCHLD signal.

PreviousSleepNextWait System Call

Last updated 4 months ago

Was this helpful?