Process Management

Process is allocated resources (such as main memory) and is available for scheduling.

A process is not the same as a program. Each process has a state which includes: May include accounting information and other information to be used in scheduling (priority, for example).

Process creation -- Parent process creates (or requests OS to create) a child process. One parent can have several children.

In UNIX, this is done by a fork system call. Child gets new memory containing a copy of parent's memory (to allow communication to child). This can be expensive. Both start execution at instruction right after fork call; return code to child is 0, to parent is child's process id (or -1 if err); fork is a c function which returns a value.

So the code typically tests the return code returned by the fork call; if the code is 0, (that is, this is the child executing), it executes an execve system call to load another file into memory and start its execution.

Parent may either wait or continue (remember "&" at end of a command line? This tells the shell program whether or not to wait for child to complete.)

Schedulers

CPU burst -- "Typical" amount of execution time until a process must wait (e.g. it issues an I/O request).

     f   |     . . 
     r   |   .     .
     e   |  .        .
     q   | .           .
     .   |.                 .      .
         +---------------------------------
            Execution time til interrupt
Context switch -- Switch CPU from one process to another. Involves overhead. These occur frequently and hence should be very fast. Usually involves hardware support, e.g. one instruction to save all register contents to memory (to PCB). Also may involve several sets of registers.

Scheduling Algorithms -- Several are presented below. Their evaluation involves several criteria:

First Come First Serve (FIFO)

Shortest Job First (SJF)

Priority Scheduling -- Ready queue maintained in priority order, where priority of a process is:

Round Robin Scheduling -- Fixed time slice to each waiting process.

Considerations for schedulers:

  1. possibility of starvation
  2. possibility of deadlock (normally not a problem with dispatcher)
  3. overhead of context switching (what is the "optimal" size of the "quantum."
  4. runtime overhead of scheduling algorithm (much more of a concern for the dispatcher, less so for the job scheduler).
Other approaches:

Multiple queues
         high priority
          ^             +------------------+
          |       ----->| system processes |----->
          |             +------------------+
          |             +------------------+
          |       ----->| interactive proc |----->
          |             +------------------+
          |             +------------------+
          |       ----->| batch processes  |----->
          |             +------------------+
         low priority
So system processes (which are "ready") are run before any interactive processes. And batch processes only run if there are no "ready" system or interactive processes. (This same thing can be done with a single queue kept in order by process type, so the use of multiple queues is in part an implementation technique which would be justified based on speed.)

Direct assignment -- for example
50% of CPU goes to interactive processes
20% of CPU goes to batch processes,
30% of CPU goes to real-time process.
Typically done with separate queues for each process type, and choose which queue to use based on recent CPU utilization for each type (e.g. in the last 100 milliseconds, interactive processes have gotten a total of 50 milliseconds, real-time 30 milliseconds and batch only 10 milliseconds, so pick the next process off of the ready queue for batch processes.

Multilevel feedback queues
         new     +-----------+                         ^ high priority
       --------->|           |--       quantum = 8     |
                 +-----------+  \                      |
             /------------------/                      |
             \   +-----------+                         |
              ---|           |--       quantum = 32    |
                 +-----------+  \                      |
             /------------------/                      |
             \   +-----------+                         |
              ---|           |         preemptive FCFS |
                 +-----------+                         |
The idea is that all newly arriving processes get a quick slice of the CPU (we may allow the process to circulate through the highest priority queue two or three times) so if the process is short, it finishes very quickly. But if the process requires more CPU time if will not finish in this first few tries and will drop to a lower priority queue. Very long running processes will eventually be moved to the bottom queue and only run when the higher priority queues are empty. This tends to give quick response time to very short tasks, and automatically give low priority to long running processes.

Evaluation of alternative scheduling concepts: Since OSs have been around for a long time now, much work has been done evaluating different ideas for scheduling. The techniques for doing this include:


Index Previous Next

Copyright ©2017, G. Hill Price
Send comments to G. Hill Price