Processes
We began an in-depth discussion of processes and process management.
- A process is created by the OS when a user requests that a program be executed.
- The OS then locates the executable code for the program in its file system on disk, and constructs an virtual memory execution enviornment of the program with
- its code,
- room for static variables,
- a stack for managing function (method) calls, and
- a heap for managing dynamic data, such as objects, that are created and removed in arbitrary fashion.
- This executable view is laid out as if the whole thing would take up all of addressasble memory (e.g., 4 gigabytes on a processor that deals with 32 bit addresses, because 2^32 is 4G). This is just a virtual memory view. The OS will use its virtual memory management software along with hardware support for virtual memory to map parts of this process to real RAM as needed.
- The OS also creates a data structure, sometimes referred to as a process control block, or PCB, for managing the process as it executes. The PCB can be thought of as an object with methods for chaning its data fields (attributes). It is rather complex and will contain such things as
- a unique process identifier (PID) number
- a field for storing the PC value when the process is to stop execution (so that the PC can later be restored when the process is set by the OS to run again later)
- fields for all data registers so that they can be saved and restored as this process is stopped and later restarted by the OS.
- fields for all other values that need saved, such as the PSR (program status register), the virtual memory tables for this process, and so forth
- fields for linking this process in various queues, such as "ready to run," "waiting for an event," etc.