Process Image

Processes and Resources
P1
CPU
P2
I/O
P3
I/O
Main
memory
Virtual memory
Resources
• OS = software that manages the resources
used by processes.
• What information does an OS need to control
processes and manage resources for them?
1
OS Control Structure
• An OS constructs and maintains tables of information about
each entity (process/resource) that it manages.
– Four tables for memory, I/O devices, files and processes
Memory
Memory Table
I/O Devices
I/O Table
Files
File Table
Processes
Process Image
(core image)
Process
1
Process Table
Process 1
Process 2
……
Process
n
Process n
2
Core Dump
• When a program crashes, an OS generates a
core dump (process image).
• Core dump
– A set of information on a crashed process
– Used for debugging programs.
3
Note that…
• Four tables are cross-referenced.
• An OS obtains some basic information on the
underlying system environment when it is
initialized (during the boot-up process).
– e.g. The total memory size
– The existence of CPU(s) and their identifiers
• How many CPUs?
– The existence of I/O devices and their identifiers
• HDD, CD/DVD-ROM, etc.
– Via some configuration data with human assistance
• e.g. BIOS (Basic Input/Output System)
4
Memory Table
• Keeps track of both main and virtual memory.
– Some of main memory is reserved for an OS.
• Maintains
– The allocation of main and virtual memory to
processes
• i.e, which processes uses which memory segments
– Any protection attributes of segments of main or
virtual memory
• E.g. which processes may access certain shared memory
space.
5
I/O Table
• Keeps track of I/O devices and channels
• Maintains
– A set of I/O devices and channels
– The status of each I/O operation
– The location in main memory being used as the
source and destination of the I/O transfer.
• e.g., standard input, standard output, standard error
– java.lang.System
» System.in, System.out, System.err
» System.setIn(), System.setOut(), System.setErr(),
6
File Table
• Keeps track of files
• Maintains
– The existence of files
– The location of each file on main and virtual
memory
– The current status of each file
• open, closed, etc.
7
Process Image
• Process image created for each process
• Each process image consists of 4 elements
– User program
• The program to be executed.
– User data
• The mutable part of memory. Includes program data and a user stack.
– Used to keep track of procedure calls and parameter passing between
procedures.
– Kernel stack
• Used to keep track of system calls and parameter passing.
– Process control block (PCB)
• Data needed by an OS to control a process (a set of attributes of a process)
8
Process Image
Process
Control
Block
User Program
User Data/Stack
Kernel Stack
• PCB: the most important data
structure in an OS
– Process identification
• PID
– CPU state information
• The contents of CPU registers
• Program counter
– Indicates the address of the next
instruction to be executed.
– Process control information
• Event that a process is waiting on.
• I/O status (e.g., open files)
• Scheduling info
9
• Each process image exists in main memory or
virtual memory.
– In contiguous or uncontiguous blocks of memory.
– These blocks may be of variable length (called
segments), fixed length (called pages), or a
combination.
• To execute a process, the entire process image
must be loaded into main memory.
• When a process is swapped out, a part of its
process image may remain in main memory.
– To speed up reloading the image to main memory.
10
Revised Design of Process Table
Processes
Process Table
Process
Image
Running
Ready
Blocked
Process
Image
Process
Image
Process
Image
Process
Image
Process
Image
Linked List or array structure
11
Process Images and CPU Switch
Process 1
Running
OS (Process Scheduler)
Process preemption (context switch)
or I/O operation
Process 2
Ready
Save the process image for P1
Running
Ready
Load the process image for P2
Save the process image for P2
Running
Load the process image for P1
Ready
12
Process Creation
New
admitted
Dispatched to a CPU
activated
Ready,
Suspended
exit
Ready
Running
Terminated
Suspended
interrupted
Event completion
Blocked,
Suspended
activated
I/O or event wait
Blocked
Suspended
• Assign a unique process ID (pid) to a new process.
13
14
• A new entry is added to the process table, which contains one
entry per process.
• Allocate memory space for the process and create a process
image. Initialize all elements of the process image.
• Place the created process image to a process queue (Ready,
Suspended).
Memory
Memory Table
I/O Devices
I/O Table
Files
File Table
Processes
Process Table
Running
Ready, Suspended
Process
Image
……
Process
Image
Process
Image
15
Process Switch (Context Switch)
Process 1
Running
OS
Process preemption
or I/O operation
Process 2
Ready
Save the process image for P1
Running
Ready
or Blocked
Load the process image for P2
Save the process image for P2
Running
Load the process image for P1
Ready
16
HW5
• Learn core dumps.
• Choose an OS, and describe
– how the OS generates a core dump
– what information is included in a core dump.
17