Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Lecture 2

Dr. Subhi A.Rahim


Bahudaila OS
Processes
2 Lecture 2

 A process is a program in execution. In general a process will


need certain resources, e.g., CPU time, memory, files & I/O
devices to accomplish a particular task. These resources are
allocated to the task either when it is created or while it is
executing.
 The o/s is responsible for process management:
 Creation & termination of processes (user + System)
 Interleaving the execution of processes
 Scheduling of processes
 Synchronization mechanism between processes
 Communication
 Deadlock handling
Process Elements
3 Lecture 2

 While the program is executing, this process can be uniquely


characterized by a number of elements, including:.
Process Control Block
4 Lecture 2

 Contains the process elements


 It is possible to interrupt a running
process and later resume execution as
if the interruption had not occurred
 Created and managed by the
operating system
 Key tool that allows support for
multiple processes
Process Execution
5 Lecture 2

 From processors point of view a


process will perform its job in
some sequence dictated by the
changing values in a register
known as program counter (PC)
or instruction pointer.
 Example in which three processes
are residing in the memory, in
addition to these processes, a
program called dispatcher is also
loaded into the memory which
basically moves the processor
from one process to another
process, the situation is shown the
figure.
Traces of Processes
6 Lecture 2

Process trace: the behavior of a


process can be visualized by listing
the sequence of instructions that
execute the process or task, such a
listing is called trace of the process.

Example: The individual traces of


three processes. There are :
• 12 instructions for process A,
• 4 instructions for process B after
which it invokes an I/O operation,
• 12 instructions for process C.
• The Job of the dispatcher is to
switch the processor from one
process to another process after
every six instructions,
7

Processors
point of view:
Combined
Trace of
Processes
The Process Model
8 Lecture 2

 The principal responsibility of an OS is to control the execution of processes.


The most simplest model one can imagine about the states of a process could
be; either a process is running (executing) or it is not running (not
executing/idle) as shown Fig.(a). When new processes enter in the system, the
dispatcher schedule these processes, that is moving a non executing process to
executing state & vice versa. Therefore, the system has to keep track of the
processes with their states, means when they are scheduled next time they must
start executing from where they were terminated.
 The Process Model
9 Lecture 2

 Now if multiple processes are around the question is which process to execute,
the simplest approach could be using a queue in which the suspended processes
are lined up as shown in Fig.(b) (one thing must be remembered here that all
these processes are in a state that when they are selected from the queue (FIFO
fashion) they directly go to execution state) and the system execute them in a
FIFO fashion when there turn comes. The processes are being executed in a
Round Robin technique, that is each process is executed for a given amount of
time.
 Five-State Process Model
10 Lecture 2

 To have more natural look towards the states of a process the following model with five
states are presented:
New: A process that has just been created & is not admitted to the pool of executable
processes by the operating system. • Exit: A process that has been released from the pool of
executable processes by the o/s, either because it is halted or aborted for some reason. •
Executing: Instructions are being executed. • Ready: The process is waiting its turn to go
into execution by the processor. • Blocked: The process is temporarily suspended, waiting
for some event to occur, e.g., an I/O function..
Creating & Termination Processes
11 Lecture 2

Typically there are four commonly known instances responsible for creating
processes:
 New Batch Job: A process is created in response to the submission of a job,
also a new process can be created when processor is ready to accept another
assignment.
 Interactive Log on: In a networking system when a user logon a process is
created.
 To provide a Service: In this case a process is created on behalf of the
application, e.g., if a user wants to print a file, a process can be created on
behalf of an application to print that file.
 Creating & Termination Processes
12 Lecture 2

 Branching & Spawning: In general o/s creates processes in a way that it is


transparent from the user or application program. However, it is also true that a
process can create another process, this type of process creation is called
process spawning. The process that creates a process is called parent process &
the created process is called the child process. Also the created process (child)
runs normally in parallel with the parent process. Another aspect of the
spawning processes is that they need to communicate & cooperate with each
other.
Following are the events lead to terminate a particular process:
 Normal Completion, Time Limit, Memory Not Available, Address Space
Violation, Protection Error, Arithmetic Overflow, I/O Failure, Invalid
Instruction, Privileged Instruction, Operator/OS Intervention, Parent Request
Termination, & Parent Termination.
Process Image
13 Lecture 2

Each process image consists of a process control block, a user


stack, the private address space of the process, and any other
address space that the process shares with other processes. In
an actual implementation, this may not be the case; it will
depend on the memory management scheme and the way in
which control structures are organized by the OS.
14
Execution of Operating System
15 Lecture 2

Is the OS a process? If so, how is it controlled?


These interesting questions have inspired a number of
design approaches that are found in various
contemporary operating systems, which are described the
Relationship between Operating System and User
Processes as:
 Non-Process Kernel.
 Operating System With in User Processes.
 Process Based Operating System
 Non-Process Kernel
16 Lecture 2

It is quite traditional approach & is common on many older


operating systems. The kernel is executed outside of any process.
The key in this case is that kernel is separate identity & operates in
privilege mode & the concept of process is applied to the user &
application programs. This mean when ever the control is
transferred in each direction a process switch occurs
 Operating System With in User Processes
17 Lecture 2

This type of system is common on mini & microcomputers, in such


systems virtually all the operating system software executes in context
with a user process.
 Process Based Operating System
18 Lecture 2

In this scheme the operating system is implemented as a collection of


system processes and the process switching code is executed outside of
any process.
This scheme is quite useful, because it allows a modular approach o/s
designed with minimal, clean interfaces between the modules.
Implementing the o/s as a set of processes is useful in a
multiprocessor or multi-computer environment in which some of the
services can be shipped out to dedicated processors, thus improving
performance.

You might also like