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

OS__Lecture___3__(Process__Mgmt.)(1)

Uploaded by

daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

OS__Lecture___3__(Process__Mgmt.)(1)

Uploaded by

daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 14

Topic: Process Management

College of Engineering, Technology, and Computational Sciences

Department of Computer Science

Course Title: Operating system


Lecture 3 Topic: Process management
Learning objectives
 To introduce process concept
 To identify methods for process scheduling
 To explain the features of:
a) process creation,
b) process termination,
c) process cooperation.
 To differentiate various Process Scheduling Algorithms (FCFS, SJF, Priority, RR)

 Operating System - Process Concept


Process
Process is a program in execution; process execution must progress in sequential fashion.
We write our computer programs in a text file and when we execute this program, it becomes a
process which performs all the tasks mentioned in the program. When a program is loaded into the
memory and it becomes a process, it can be divided into four sections ─ stack, heap, text and data.
The following image shows a simplified layout of a process inside main memory:

The memory layout of a process is typically divided into multiple


sections, which include:
 The program code, also called text section
 Current activity including program counter, processor
registers
 Stack containing temporary data
 Function parameters, return addresses, local
variables
 Data section containing global variables

Fig. 3.1 Layout of a process in memory.

 Process State
Source: Feleke Merin (Dr. – Engr.) Page 1 of 14
Topic: Process Management
As a process executes, it changes state. The state of a process is defined in part by the current
activity of that process. A process may be in one of the following state:
New. The process is being created.
Ready. The process is waiting to be assigned to a processor.
Running. Instructions are being executed.
Waiting. The process is waiting for some event to occur (such as an I/O completion or reception of a signal).
Terminated. The process has finished execution.

It is important to realize that only one process can be running on any processor core at any instant.
Many processes may be ready and waiting, however. The state diagram corresponding to these
states is presented in Figure below.

 Process State Transitions


The transition from one job or process status to another is initiated by either the Job
Scheduler or the Process Scheduler:
 The transition from NEW to READY is initiated by the Job Scheduler according to
some predefined policy. At this point the availability of enough main memory and any
requested devices are checked.

 The transition from READY to RUNNING is handled by the Process Scheduler


according to some predefined algorithm (i.e., FCFS, SJN, priority scheduling,
SRT, or round robin-all of which will be discussed shortly).
Source: Feleke Merin (Dr. – Engr.) Page 2 of 14
Topic: Process Management

 The transition from RUNNING back to READY is handled by the Process


Scheduler according to some predefined time limit, or other criterion, for
example, a “priority” interrupt.
 The transition from RUNNING to WAI I ING is handled by the Process Scheduler and
is initiated by an instruction in the job such as a command to READ or WRITE or
other 1/0 request, or one that requires a page fetch

 The transition from WAITING to READY is handled by the Process Scheduler and is
initiated by a signal from the I/O device manager that the I/O request has been
satisfied and the job can continue. In the case of a page fetch, the page interrupt
handler will signal that the page is now in memory and the process can be placed on
the READY queue.

 Eventually, the transition from RUNNING to FINISHED is initiated by the Process


Scheduler or the Job Scheduler either when:
– the job is successfully completed and it ends execution or
– the operating system indicates that an error has occurred and the job is being
terminated prematurely.

 Process Control Block (PCB)


A Process Control Block is a data structure maintained by the Operating System for every process.
The PCB is identified by an integer process ID (PID). A PCB keeps all the information needed by
the OS to keep track of a process as listed below in the table. The architecture of a PCB is
Source: Feleke Merin (Dr. – Engr.) Page 3 of 14
Topic: Process Management
completely dependent on Operating System and may contain different information in different
operating systems. Here is a simplified diagram of a PCB:

The PCB is maintained for a process throughout its lifetime, and is deleted once the process terminates.

 Information contained in the PCB


PCB contains many pieces of information associated with a specific process, including these:
 Process ID. Unique identification for each of the process in the operating system.
 Process state. The current state of the process i.e., it may be new, ready, running, waiting,
halted, and so on.
 Process priority. Process priority used by systems using a priority scheduling algorithm
to select which job will be run next.
 Program counter. The counter indicates the address of the next instruction to be executed
for this process.
 CPU registers. The registers vary in number and type, depending on the computer
architecture. They include accumulators, index registers, stack pointers, and general-
purpose registers, plus any condition-code information. Along with the program counter,
this state information must be saved when an interrupt occurs, to allow the process to be
continued correctly after ward when it is rescheduled to run.
Source: Feleke Merin (Dr. – Engr.) Page 4 of 14
Topic: Process Management
 CPU-scheduling information. This information includes a process priority, pointers to
scheduling queues, and any other scheduling parameters.
 Memory-management information. This information may include such items as the value of
the base and limit registers and the page tables, or the segment tables, depending on the
memory system used by the operating system.
 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.
 Accounting information. This information includes the amount of CPU and real time used,
time limits, account numbers, job or process numbers, and so on.

 Accounting. Contains information used mainly for billing purposes and performance
measurement. It indicates what kind of resources the job used and for how long.
Typical charges include:
1. Amount of CPU time used from beginning to end of its execution
2. Total time the job was in the system until it exited.
3. Main storage occupancy, how long the job stayed in memory until it finished
execution. This is usually a combination of time and space used, for example, in
a paging system it may be recorded in units of pageseconds.
4. Secondary storage used during execution. This again is recorded as a
combination of time and space use.
5. System programs used such as compilers, editors, or utilities.
6. Number and type of I/0 operations, including I/O transmission time, that
includes utilization of channels, control units, and devices.
7. Time spent waiting for I/O completion.
8. Number of input records read (specifically those entered on-line or coming from
optical scanners, card readers, or other input devices), and number of
output records written (specifically those sent to the line printer). This last
one distinguishes between secondary storage devices and typical 1/0 devices.
 Contains information associated with each process
 Process State - e.g. new, ready, running etc.
Process Control Block (summary)
 Process Number – Process ID
 Program Counter - address of next instruction to be executed
 CPU registers - general purpose registers, stack pointer etc.
 CPU scheduling information - process priority, pointer
 Memory Management information - base/limit information
 Accounting
Source: Feleke Merin (Dr. information
– Engr.) - time limits, process number
Page 5 of 14

 I/O Status information - list of I/O devices allocated


Topic: Process Management

 Process Scheduling Policies


In a multiprogramming environment, there are usually more jobs to be executed than
could possibly be run at one time. Before the operating system can schedule them, it needs
to resolve three limitations of the system:

1. there is a finite number of resources (such as disk drives, printers, and tape-drives);

2 . some resources, once they're allocated, can't be shared with another job (such as
printers); and

3. some resources require operator intervention that is, they can't be reassigned
automatically from job to job (such as tape drives).

What's a “good” process scheduling policy? There are several criteria that come to mind, but
notice in the list below that some of them contradict each other:

1. Maximize throughput by running as many jobs as possible m a given amount of time.


This could be accomplished easily by running only short jobs or by running jobs
without interruptions.
2. Minimize response time by quickly turning around interactive requests. This could be
done by running only interactive jobs and letting the batch jobs wait until the
interactive load ceases.
3. Minimize turnaround time by moving entire jobs in and out of the system quickly. This
could be done by running all batch jobs first (because batch jobs can be grouped to run
more efficiently than interactive jobs).
4. Minimize waiting time by moving jobs out of the READY queue as quickly as possible.
This could only be done by reducing the number of users allowed on the system so the
CPU would be available immediately when ever a job entered the READY queue.

Source: Feleke Merin (Dr. – Engr.) Page 6 of 14


Topic: Process Management
5. Maximize CPU efficiency by keeping the CPU busy I 00% of the time. This could be
done by running only CPU-bound jobs (and not I/0- bound jobs).

6. Ensure fairness for all jobs by giving everyone an equal amount of CPU and I/O time.
This could be done by not giving special treatment to any job, regardless of its
processing characteristics or priority.

As we can see from this list, if the system favors one type of user then it hurts another or
doesn't efficiently use its resources. The final decision rests with the system designer, who must
determine which criteria are most important for that specific system. For example, you might
decide to maximize CPU utilization while minimizing response time and balancing the use of
all system components through a mix of I/O-bound and CPU-bound jobs." So you would select
the scheduling policy that most closely satisfies your criteria.

Although the Job Scheduler selects jobs to ensure that the READY and I/O queues remain
balanced, there are instances when a job claims the CPU for a very long time before issuing an
I/O request. If I/O requests are being satisfied (this is done by an I/O controller and will be
discussed later), this extensive use of the CPU will build up the READY queue while emptying
out the I/O queues, which creates an unacceptable imbalance in the system.

To solve this problem the Process Scheduler often uses a timing mechanism and periodically
interrupts running processes when a predetermined slice of time has expired. When that
happens, the scheduler suspends all activity on the currently running job and reschedules
it into the READY queue; it will be continued later. The CPU is now allocated to another job that
runs until one of three things happens: the timer goes off, the job issues an 1/0 command, or
the job is finished. Then the job moves to the READY queue, the WAIT queue, or the FINISHED
queue, respectively. An I/O request is called a "natural wait" in multiprogramming
environments (it allows the processor to be allocated to another job).

A scheduling strategy that interrupts the processing of a job and transfers the CPU to another
job is called a preemptive scheduling policy, and it is widely used in time-sharing environments.
The alternative, of course, is a nonpreemptive scheduling policy, which functions without
Source: Feleke Merin (Dr. – Engr.) Page 7 of 14
Topic: Process Management
external interrupts (interrupts external to the job). Therefore once a job captures the processor
and begins execution, it remains in the RUNNING state uninterrupted until it issues an 1/0
request (natural wait) or it is finished (with exceptions made for infinite loops, which are
interrupted by both preemptive and non preemptive policies).

 Operating system - Process Scheduling


 The process scheduling is the activity of the process manager that handles the removal of the
running process from the CPU and the selection of another process on the basis of a
particular strategy.

 Process scheduling is an essential part of a Multiprogramming operating systems. Such


operating systems allow more than one process to be loaded into the executable memory at a
time and the loaded process shares the CPU using time multiplexing.

 The OS maintains a separate queue for each of the process states and PCBs of all processes
in the same execution state are placed in the same queue. When the state of a process is
changed, its PCB is unlinked from its current queue and moved to its new state queue.

 Process Scheduling (note)


 The goal of multiprogramming  Maximize CPU/resource utilization!
 The goal of time sharing  Allow each user to interact with his/her program!

 Process scheduling queues


The Operating System maintains the following important process scheduling queues:
 Batch queue (or Job queue) - This queue keeps all the processes in the system.

Source: Feleke Merin (Dr. – Engr.) Page 8 of 14


Topic: Process Management
 Ready queue - This queue keeps a set of all processes residing in main memory, ready and
waiting to execute. A new process is always put in this queue.
 Suspended queues - The processes which are blocked due to unavailability of an I/O device
constitute this queue.

The OS can use different policies to manage each queue (FIFO, Round Robin, Priority, etc.). The OS
scheduler determines how to move processes between the ready and run queues which can only have one
entry per processor core on the system; in the above diagram, it has been merged with the CPU.

 Schedulers (Process migration between the various queues)


Schedulers are special system software which handle process scheduling in various ways. Their
main task is to select the jobs to be submitted into the system and to decide which process to run.
Schedulers are of three types:
1. Long-Term Scheduler
2. Short-Term Scheduler
3. Medium-Term Scheduler

a) Long-Term Scheduler key features:


 It is also called a job scheduler.
 A long-term scheduler determines which programs are admitted to the system for
processing.

Source: Feleke Merin (Dr. – Engr.) Page 9 of 14


Topic: Process Management
 It selects processes from the Job queue (or batch queue) and loads them into ready queue
(or memory0 for execution.
 invoked very infrequently (seconds, minutes); may be slow.
 The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O
bound and processor bound.
– I/O-bound process – spends more time doing I/O than computations, many short CPU bursts.
– CPU-bound process – spends more time doing computations; few very long CPU bursts.
 It also controls the degree of multiprogramming. If the degree of multiprogramming is
stable, then the average rate of process creation must be equal to the average departure rate
of processes leaving the system.
 On some systems, the long-term scheduler may not be available or minimal.
 Time-sharing operating systems have no long term scheduler.
 When a process changes the state from new to ready, then there is use of long-term scheduler.

b) Short-Term Scheduler key features:


 It is also called as CPU scheduler.
 Its main objective is to increase system performance in accordance with the chosen set of
criteria.
 It is the change of ready state to running state of the process.
 CPU scheduler selects a process among the processes that are ready to execute and allocates
CPU to one of them.
 Short-term schedulers, also known as dispatchers, make the decision of which process to
execute next.
 Short-term schedulers invoked very frequently (milliseconds) - must be very fast
 Short-term schedulers are faster than long-term schedulers.

c) Medium-term scheduler key features


 Medium-term scheduling is a part of swapping.
 It removes the processes from the memory.
 It reduces the degree of multiprogramming.

Source: Feleke Merin (Dr. – Engr.) Page 10 of 14


Topic: Process Management
 The medium-term scheduler is in charge of handling the swapped out-processes(the
suspended process is moved from memory to the secondary storage).
 A running process may become suspended if it makes an I/O request.
 A suspended processes cannot make any progress towards completion.
 Swapping may be necessary to improve the process mix.

 Comparison among Schedulers

 Process Context Switch


Switching the CPU core to another process requires performing a state save of the current process and a
state restore of a different process. This task is known as a context switch and is illustrated in Fig. below.

Source: Feleke Merin (Dr. – Engr.) Page 11 of 14


Topic: Process Management
When the scheduler switches the CPU from executing one process to execute another, the state from
the current running process is stored into the process control block. After this, the state for the
process to run next is loaded from its own PCB and used to set the PC, registers, etc. At that point,
the second process can start executing.

Using this technique, a context switcher enables multiple processes to share a single CPU. Context
switching is an essential part of a multitasking operating system features.

Context switch time is pure overhead, because the system does no useful work while switching.
Switching speed varies from machine to machine, depending on the memory speed, the number of
registers that must be copied, and the existence of special instructions (such as a single instruction
to load or store all registers). Atypical speed is a several microseconds.

Context switches are computationally intensive since register and memory state must be saved and restored.
Context-switch time is overhead; the system does no useful work while switching.
Context-switch time dependent on hardware support.

 Operation on Processes
 Process creation
There are four principal reasons that cause processes to be created:
Source: Feleke Merin (Dr. – Engr.) Page 12 of 14
Topic: Process Management

i) System initialization – processes created at boot time, “background processes”, also called
daemon processes. (daemon processes: processes that stay in the background to handle
some activity such as e-mail, Web pages, news, printing, and so on)

ii) Execution of a process creation system call by a running process - a running process will issue
system calls to create one or more new processes to help it do its job.

iii) A user request to create a new process – a user can start a program (to be executed) by
(double) clicking an icon or typing a command.

iv) Initiation of a batch system – process creation applies to the batch systems (found on large
mainframes). Here users can submit batch jobs to the system (possibly remotely). When the
operating system decides that it has the resources to run another job, it creates a new
process and runs the next job from the input queue I it.
Q: What are the actions performed by the operating system when a new process is created?
Answer: OS performs the following actions when a new process is created:
1. Create a process control block (PCB) for the process
2. Assign process ID and priority
3. Allocate memory and other resources to the process
4. Set up the process environment (loading the process code in the memory (ready queue), …)
5. Initialize resource accounting information for the process.

 Reasons for process termination


i) Normal exit (voluntary) – to indicate a process is finished (Example: user logs off )
ii) Error exit (voluntary) – invalid or privileged instruction (Example: no such file exists)
iii) Fatal error (involuntary) – often due to a program bug (Example: division by zero)
iv) Killed by another process (involuntary) – In UNIX kill; in Win32 function TerminateProcess

 Cooperating Processes
- The processes executing in the operating system may be either independent processes or
cooperating processes.

- A process is independent if it cannot affect or be affected by the other processes executing in


the system. (or any process that does not share data with any other process is independent.)

Source: Feleke Merin (Dr. – Engr.) Page 13 of 14


Topic: Process Management

- A process is cooperating if it can affect or be affected by the other processes executing in the
system.

- There are several reasons for providing an environment that allows process cooperation:

i) Information sharing – E.g.: a shared file (we must provide an environment to allow
concurrent access to such information)

ii) Computation speed-up – We must break a particular task into subtasks, each of which will
be executing in parallel with the other.

i) Modularity – Dividing the system functions into separate processes or threads.

iv) Convenience – a individual user may work


on many tasks at the same time. Example: a user may be editing, printing, and compiling in
parallel.

----------------------------------------The End! -----------------------------------

Source: Feleke Merin (Dr. – Engr.) Page 14 of 14

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy