0% found this document useful (0 votes)
18 views

OS Lecture2

Uploaded by

adiasaraf29
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

OS Lecture2

Uploaded by

adiasaraf29
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

LECTURE 2

PROCESSES

Instructor : Dr.Fouzia Idrees


Processes
2

 Process Concept
 Process Scheduling
 Operations on Processes
Objectives
3

 To introduce the idea of a process -- a


program in execution, which forms the basis
of all computation

 To describe the various features of processes,


including scheduling, creation and
termination, and communication
Process Concept
4

 An operating system executes a variety of programs:


 Batch system – jobs
 Time-shared systems – user programs or tasks
 Textbook uses the terms job and process almost
interchangeably
 Process – a program in execution; process execution must
progress in sequential fashion
 A process includes:
 Text section
 Program counter
 Stack
 Data section
 Heap
The Process
5

 Multiple parts
 The text section comprises the compiled program code, read in
from non-volatile storage when the program is launched.
 It also includes the current activity, as represented by the value of
the program counter and the contents of the processor’s
registers.
 A Stack containing temporary data
 Function parameters, return addresses, local variables
 Data section containing global variables
 Heap containing memory dynamically allocated during run time
6

 Program is passive entity, process is active


 Program becomes process when executable file loaded
into memory
 Execution of program started via GUI mouse clicks,
command line entry of its name, etc
 One program can be several processes
 Consider multiple users executing the same program
Process in Memory
7
Process State
8

 As a process executes, it changes state


 new: The process is being created
 running: Instructions are being executed
 waiting: The process is waiting for some event to occur
 ready: The process is waiting to be assigned to a
processor
 terminated: The process has finished execution
Diagram of Process State
9
Process Control Block (PCB)
10

Information associated with each process


 Process State - Running, waiting, etc., as discussed above.
 Program Counter - A program counter is a register in a computer
processor that contains the address (location) of the instruction being
executed at the current time. As each instruction gets fetched, the
program counter increases its stored value by 1. After each instruction is
fetched, the program counter points to the next instruction in the
sequence. When the computer restarts or is reset, the program counter
normally reverts to 0.
11

 CPU registers -- The registers vary in number and type, depending on the
computer architecture
 CPU-Scheduling information - Such as priority information and pointers to
scheduling queues.
 Memory-Management information - E.g. page tables or segment tables.
 Accounting information - This information includes the amount of CPU and real
time used, time limits, account numbers, job or process numbers, and so on.
 I/O Status information - This information includes the list of I/O devices allocated
to the process, a list of open files, and so on.

CUSIT 2015
Process Control Block (PCB)
12
CPU Switch From Process to Process
13
Process Scheduling
14

 Maximize CPU use, quickly switch processes onto CPU


for time sharing
 Process scheduler selects among available processes for
next execution on CPU
 Maintains scheduling queues of processes
 Job queue – set of all processes in the system
 Ready queue – set of all processes residing in main memory,
ready and waiting to execute
 Device queues – set of processes waiting for an I/O device
 Processes migrate among the various queues
Representation of Process Scheduling
15
Schedulers
16

 Long-term scheduler (or job scheduler) – selects


which processes should be brought into the ready queue
 Short-term scheduler (or CPU scheduler) – selects
which process should be executed next and allocates
CPU
 Sometimes the only scheduler in a system
Schedulers (Cont.)
17

 Short-term scheduler is invoked very frequently


(milliseconds)  (must be fast)
 Long-term scheduler is invoked very infrequently (seconds,
minutes)  (may be slow)
 The long-term scheduler controls the degree of
multiprogramming
 Processes can be described as either:
 I/O-bound process – spends more time doing I/O than
computations
 CPU-bound process – spends more time doing computations
Addition of Medium Term Scheduling
18

 Medium term scheduling is part of the swapping. It removes


the processes from the memory. The medium term scheduler
is in-charge of handling the swapped out-processes.
Context Switch
19

 When CPU switches to another process, the system must save the state of
the old process and load the saved state for the new process via a context
switch.

 Context of a process represented in the PCB

 Context-switch time is overhead; the system does no useful work while


switching
 The more complex the OS and the PCB -> longer the context switch

 Time dependent on hardware support


 Some hardware provides multiple sets of registers per CPU -> multiple
contexts loaded at once
Operations on Processes
20

Process Creation
 During the course of execution, a process may create several new
processes. The creating process is called a parent process, and the new
processes are called the children of that process. Each of these new
processes may in turn create other processes, forming a tree of processes.
 Process identified and managed via a process identifier (pid)
 Resource sharing
 Parent and children share all resources
 Children share subset of parent’s resources
 Parent and child share no resources
 Execution
 Parent and children execute concurrently
 Parent waits until children terminate
Process Creation (Cont.)
21

 Address space
 Child duplicate of parent
 The child process has a new program loaded into it.

 UNIX examples
 fork system call creates new process
 exec system call used after a fork to replace the process’
memory space with a new program
Process Creation
22
A Tree of Processes on Solaris
23
24

Process Termination
 Process executes last statement and asks the operating system to
delete it (exit)
 Output data from child to parent (via wait)
 Process’ resources are reallocated by operating system

 Parent may terminate execution of children processes (abort)


 Child has exceeded allocated resources
 Task assigned to child is no longer required
 If parent is exiting
 Some operating systems do not allow child to continue if its parent terminates
 All children terminated - cascading termination
END OF THE LECTURE

You might also like