Professional Documents
Culture Documents
Lecture #2
Review of Relevant Topics (Process Concept)
Communication b/w processes
S. Zaffar Qasim
Assistant Professor (CIS)
Process Description
A fundamental question: What information does the OS need
to control processes and manage resources for them?
Operating System Control Structures
The OS constructs and maintains tables of information
about each entity that it is managing.
Four different types of tables maintained by the OS:-
o memory,
o I/O,
o file and
o process.
OS Control Structures
PCB
• Process identifier is useful in several ways.
a. Many of the other tables controlled by the OS may use
process IDs to cross-reference process tables.
b. When processes communicate with one another, the
process ID informs the OS of the destination of a
particular communication.
c. When processes create other processes, identifiers
indicate the parent and descendants of each process.
2. Processor State Information
It consists of the contents of processor registers.
When a process is interrupted, all of register information
must be saved so that it can be restored when the process
resumes execution.
The register set will include user-visible registers, control and
status registers and stack pointers. 10
11
PCB
Data Structuring
• A process may be linked to other process in a queue, ring or
some other structure.
o For example, all processes in a waiting state for a
particular priority level may be linked in a queue.
o A process may exhibit a parent-child relationship with
another process.
o The PCB may contain pointers to other processes to
support these structures.
Interprocess Communication
• Various flags, signals and messages may be associated with
communication between two independent processes.
12
Fig 3 15
16
18
19
PROCESS CONTROL
20
22
24
25
Since only system code is loaded in the system space, only system code
can be invoked by a trap.
When the OS has completed the supervisor call, it resets the mode bit to
user mode prior to the return.
26
27
Context of a process
The context of a process defined by
o its text (i.e. code),
o the values of its global user variables and data structures,
o the values of machine registers it uses,
o the values stored in its process table slot and u area, and
o the contents of its user and kernel stacks.
The text of OS and its global data structures shared by all
processes
o but do not constitute part of the context of a process.
When executing a process, the system is said to be executing
in the context of the process.
When the kernel decides that it should execute another
process, it does a context switch, so that the system executes
in the context of the other process.
28
29
Mode Switching
If an interrupt is pending, the processor does the following:-
o Saves the context of the program being executed.
o Sets the PC to the starting address of an interrupt-
handler program.
o It switched then to kernel mode so that the interrupt
processing code may include privileged instructions.
The processor now fetches the first instruction of the
interrupt-handler program.
The interrupt handler is typically a short program that
performs a few basic service tasks related to an interrupt.
For example, it resets that flag or indicator that signals the
presence of an interrupt.
It may send an acknowledgement to the entity that issued
the interrupt such as an I/O module.
30
31
32
34
36
Signals: Example
Any process Pj sends sig1 to Pi using system call signal (Pi, sig1).
The kernel locates the signal vector for sig1 through the PCB.
It now arranges for process Pi to execute the signal handler starting
at address sh1 before resuming its execution.
o saving the state of Pi,
o changing the contents of the PC to address sh1, and
o Pi would now execute the signal handler.
After that, the state of Pi reset to saved state to resume normal
operation.
38
Signals in Unix
SIGFPE (floating-point exception) signal used if a process doing
floating-point arithmetic inadvertently divides by zero.
Processes have several choices for handling signals
o ignore it,
o catch it, or
o let the signal kill the process (default for most signals).
For catching signals, process must specify a signal handling procedure.
• There is one signal (the kill signal, number 9, SIGKILL) that cannot
be ignored or caught by a signal handler.
o used, e.g., to kill a runaway process ignoring other signals such
as SIGINT or SIGQUIT.
A process can only send signals to members of its process group,
which consists of its parent (and further ancestors), siblings and
children (and further descendants).
A process may also send a signal to all members of its process
group with a single system call.
40