Sleeping Processes


Sleeping processes are placed inside of a wait queue.

The processes inside the wait queue are waiting for an event to happen.

Processes put themselves in the wait queue and mark themselves as not runnable.

A process performs the following steps to add itself to a wait queue:

  1. Creates a wait queue entry via the macro DEFINE_WAIT().
  2. Adds itself to a wait queue via add_wait_queue().This wait queue awakens the process when the condition for which it is waiting occurs.
  3. Calls prepare_to_wait() to change the process state to either TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE. This function also adds the task back to the wait queue if necessary
  4. If the state is set to TASK_INTERRUPTIBLE, a signal wakes the process up. This is called a spurious wake up (a wake-up not caused by the occurrence of the event). So check and handle signals.
  5. When the task awakens, it again checks whether the condition is true. If it is, it exits the loop. Otherwise, it again calls schedule() and repeats.
  6. Now that the condition is true, the task sets itself to TASK_RUNNING and removes itself from the wait queue via finish_wait().

An important note about sleeping is that there are spurious wake-ups. Just because a task is awakened does not mean that the event for which the task is waiting has occurred;

results matching ""

    No results matching ""