Lecture 4 -- Processes

[*]

What is a Process?

Recall a process is a copy of a program in memory, doing something.

It consists of: machine instructions, a data area, a stack, and the machine's registers it is using.

The data area holds the process' global data. The stack usually holds the process' local data, plus program counters for subroutine returns.

Layout of a Process

A typical process memory map looks like:

The map allows the stack to grow down and the data area to grow up.

Areas above/below the process' memory are invalid because of protections set by the OS.

On some machine architectures, the three sections are separated.

Process Models

Although I've said a process is in memory and doing something, often a process can't do anything, either because another process is running or it is waiting for I/O.

A state diagram shows what states a process can be in, and how it moves to new states.

On a simple monitor system, only one process in memory at any one time.

Therefore the process in memory is either running, or idle waiting for I/O.

A batch system may have many processes (jobs) in memory simultaneously, but when one is started, it runs to completion before the next can begin running.

On a multiprogramming system, the system may pre-empt a running process to allow fast and fair use of the computer.

Thus, although the CPU is running only one process at any time, the quick switching between processes makes it appear as if many are running simultaneously.

The characteristic of an interactive OS is the transition from `Running' to `Ready'.

Implementation -- Process Control Blocks

When the OS switches between processes, it must ensure the first process' bits and pieces are kept so it can be restarted.

This means:

Preserving the process' areas of memory, Protecting these from other processes, Saving copies of the registers used by the process, Saving information about other resources used, Marking the process' new state, and If blocked, for what (so when I/O completes, the process can be moved back to `Ready').

All of this information is stored in the Process Control Block in the OS. There is one PCB per process, and usually contains:

Machine dependent section:

Register copies Information about the process' memory areas

Machine independent section:

The process' state The process' priority, other scheduling information Open files and their state The process id The user id of the user running the process On what the process is blocked

Statistics section:

Total time the process has been running, etc.

The last section is used to aid the OS in deciding how/when to allocate resources to the process, as will be seen in future lectures.

An example PCB (from Minix) is:

The next lecture is on process scheduling: which process is the best to schedule next.

Warren Toomey wkt@cserve.cs.adfa.oz.au