Table of Contents
OS Nucleus and Processes
Nucleus (kernel)
- core of the OS
- lowest level of software on the central processor (CPU)
- four crucial functions:
process management,
short-term scheduling (CPU scheduling),
interrupt handling,
and
interprocess communication (IPC)
- there are routines that manage
the registers (central storage),
time, and
devices (interrupt handling)
- responds to
requests and errors from processes
(which are received as ``traps'' (sometimes called exceptions
or software interrupts))
and
requests from devices
(which are received as interrupts (true interrupts or hardware interrupts))
- some processors provide a special syscall instruction so that
system calls can be executed without causing traps
- provides the environment in which processes exist
- every process depends ultimately on the nucleus
- the term ``kernel'' is used in UNIX documentation to refer to
the combination of the nucleus, I/O, memory management,
and file system layers
PROCESSES
|
| request (sent as a trap or syscall instruction after a system call)
| or error (sent as a trap)
|
\|/
V
________________________________________________________________________
| |
| N U C L E U S |
|_______________________________________________________________________|
.
/|\
|
| request (sent as an interrupt)
|
DEVICES
Process
- a program in execution (simple definition)
- a unit of program execution with at least one thread of control
(less simple definition!)
- a process is an active entity, while a program is a static entity
Process Control Block (PCB)
- data structure used to represent one process
- the set of pcb's is called the process table
- this data structure is maintained by the nucleus
- contains all the information required to describe the current state of a program in execution
- when a process is suspended,
the OS saves the current context for execution
in the process control block for that process
- when a process is to be resumed,
the OS loads the current context for execution
from the process control block for that process
- contains:
-
process identifier (pid), which is the unique identifier
for the process--it may be implicitly known from position,
-
program counter (PC), which gives the address in main
memory of the next instruction to be executed
-
processor status (PS),
-
(other) register values,
-
process state, which might be running, ready, waiting, etc.
-
ppid = the process identifier of the parent process,
which is the process that created this one
-
scheduling information, such as priority
and pointers to scheduling queues
-
memory management info, such as limits (base and limit) and
pointers to segment or page tables,
-
accounting information,
-
open file pointers,
-
device descriptions
Example Process Control Block
Process State Graph
Switch for Interrupt Handling
- switch from running a process to running an interrupt handler,
typically followed by a switch back to running the same process
- In this type of context-switch,
the goal is to temporarily interrupt the running process to
allow an interrupt to be serviced.
Steps:
- when an interrupt occurs, the CPU first finishes the current instruction
- switch the CPU to its privileged mode (system mode)
-- this switch occurs automatically when the CPU receives an interrupt
(after finishing the current instruction)
- copy the register values for the old process to a safe place,
such as a stack (stored in memory)
- run the interrupt handler
- restore the values for the registers form the safe place,
such as the stack
- switch the CPU back to user mode
After most interrupts, the same process will resume running
- The timer interrupt may cause the scheduler to run, which may
change the states of processes from RUNNING to READY or vice versa.
Privileged mode (system mode) -
all commands (instructions) can be executed (e.g. halt) and all
memory can be accessed, including the system area
User mode -
a restricted but large subset of commands (instructions) can be executed and a
restricted area of memory can be accessed (not including the system area)
Context Switch between Processes
- switch the use of the CPU from the running process (the old process)
to a ready process (the new process).
- a ready process is a runnable process that currently does
not have the CPU, i.e., one that could run if given the CPU.
- In a context-switch,
the goal is to remove one process from the CPU
and replace it with a different process.
- Typically, the part of the OS called the CPU scheduler decides
when a context switch between processes should occur.
Steps:
- switch the CPU to its privileged mode (system mode)
- copy the register values for the old process to
the process table (stored in the OS's part of memory)
- load register values from the process table for the new process
- switch the CPU back to user mode
Table of Contents