Home > Sample essays > Exploring Processes, Schedulers & Context Switches with These Concepts

Essay: Exploring Processes, Schedulers & Context Switches with These Concepts

Essay details and download:

  • Subject area(s): Sample essays
  • Reading time: 6 minutes
  • Price: Free download
  • Published: 1 April 2019*
  • Last Modified: 18 September 2024
  • File format: Text
  • Words: 1,373 (approx)
  • Number of pages: 6 (approx)

Text preview of this essay:

This page of the essay has 1,373 words.



A process can be thought of as a program in execution. A process is the unit of the unit of work in a modern time-sharing system.

A batch system executes jobs, whereas a time-shared system has user programs or tasks. A process is more than the program code. It also includes the current activity, as represented by the value of the program counter and the contents of the processor's registers. In addition, a process generally includes the process stack, which contains temporary data (such as method parameters,return addresses, and local variables), and a data section, which contains global variables.

A program is a passive entity, such as the contents of a file stored on disk, whereas a process is an active entity, with a program counter specifying the next instruction to execute and a set of associated resources.

2.1.1 Process Concept

Let us explain the process state diagram.

Diagram of process state

Process State:

The state of a process is defined in part by the computer activity of that process. Each process may seen in the following states.

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.

• Only one process can be running on any processor at any instant.

• Many processes may be ready and waiting.

• Scheduler: selects an available process for CPU execution.

• Dispatcher: switches process from ready to running.

Process

A process is a program in execution Process includes:

•Text section: program code

•Current activity: program counter, processor registers

•Process stack: method parameters, return address, local variables

•Data section: global variables

•Heap: dynamically allocated memory

Process control Block (PCB)

•A PCB represents a process

PCB is a repository for any information that may vary from process to process.

•Process state

•Program counter

•CPU registers

•CPU-scheduling information

•Memory-management information

•Accounting information

•I/O status information

Process Control Black (PCB)

•Process state: The state may be new, ready, running, waiting, halted, and so on.

•Program Counter: The counter indicates the address of the next instruction to be executed for this purpose.

•CPU registers: The registers vary in number and types, depending on the computer architecture. They include accumulators, index registers, stack pointers, and general purpose registers, any control code information.

•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 information as the value of the base and limit registers, the page tables or the 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: The information includes the list of I/O devices allocated to this process, a list of open files and so on.

2.1.2 Process Scheduling

Process Scheduling

The objective of multiprogramming is to have some process running at all times, so as to maximize CPU utilization.

Scheduling Queues

As processes enter the system, they are put into a job queue.

The processes that are residing in main memory and are ready and waiting to execute are kept on a list called the ready queue.

This queue is generally stored as a linked list. A ready-queue header contains pointers to the first and final PCBs in the list.

Each PCB to include a pointer field that points to the next PCB in the ready queue.

Ready Queue And Various I/O Device Queues

A new process is initially put in the ready queue. It waits in the ready queue until it is selected for execution (or dispatched). Once the process is assigned to the CPU and is executing, one of several events could occur:

The process could issue an I/O request, and then be placed in an I/O queue.

The process could create a new subprocess and wait for its termination.

The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready Queue.

A common representation of process scheduling is a queueing diagram, such as that in Figure . Each rectangular box represents a queue. Two types of queues are present: the ready queue and a set of device queues. The circles represent the resources that serve the queues, and the arrows indicate the flow of processes in the system.

Representation of Process Scheduling

Schedulers

A process migrates between the various scheduling queues throughout its lifetime. The operating system must select, for scheduling purposes, processes from these queues in some fashion. The selection process is carried out by the appropriate scheduler.

In a batch system, often more processes are submitted than can be executed immediately. These processes are spooled to a mass-storage device (typically a disk), where they are kept for later execution.

The long-term scheduler, or job scheduler, selects processes from this pool and loads them into memory for execution. The short-term scheduler, or CPU scheduler, selects from among the processes that are ready to execute, and allocates the CPU to one of them.

In general, most processes can be described as either I/O bound or CPU bound.

An I\O-bound process spends more of its time doing I/O than it spends doing computations.

A CPU-bound process, on the other hand, generates I/O requests infrequently,using more of its time doing computation than an I/O-bound process uses.

The system with the best performance will have a combination of CPU-bound and I/O-bound processes.

Some operating systems, such as time-sharing systems, may introduce an additional, intermediate level of scheduling.

Addition of Medium Term Scheduling

The key idea is medium-term scheduler, removes processes from memory and thus reduces the degree of multiprogramming. At some later time, the process can be reintroduced into memory and its execution can be continued where it left off. This scheme is called swapping.

Context Switch

Switching the CPU to another process requires saving the state of the old process and loading the saved state for the new process. This task is known as a context switch. Context-switch time is pure overhead, because the system does no useful work while switching. Its 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.

Typical speeds range from 1 to 1000 microseconds.

Context-switch times are highly dependent on hardware support. A context switch simply includes changing the pointer to the current register set.

An operating System contains three resource classes, namely R1, R2 and R3. The number of resource units in these classes is 7, 7 and 10 respectively. The current resource allocation state is as shown below:

Process

Allocated

Resources

Maximum

Requirement

R1

R2

R3

R1

R2

R3

P1

2

2

3

3

6

8

P2

2

0

3

4

3

3

P3

1

2

4

3

4

4

(i)Let us see, whether the current allocation state safe or not.

(ii)Let us see whether the following requests be granted in the current state.

(1)Process P1 requests (1, 1, 0)

(2)Process P3 requests (0, 1, 0)

(3)Process P2 requests (0, 1, 0)

3 Processes (P1 through P3)

3 Resource types (R1 to R3) R1 = 7, R2= 7, R3 = 10

At time to:

P1

Allocation

R1

R2

R3

2

2

3

P2

2

0

3

P3

1

2

4

R1

Max

R2

R3

3

6

8

4

3

3

3

4

4

The content of the matrix need is defined to be max – allocation

Need

R1

R2

R3

P1

1

4

5

P2

2

3

0

P3

2

2

0

Available

R1

R2

R3

2

3

0

Safety algorithm

Work = available

Work = (2 3 0)

finish (i) = false for i = 1, 2, 3

finish [1] = false

(1,4, 5) < = (2, 3,0)

finish [2] = false

(2 3 0) < = (2, 3, 0)

True

Work = work + allocation

Work = (2 3 0) (2 0 3)

= (4 3 3)<P2,

finish [2] = true

Finish [3] = false

(2, 2, 0) < = (4 3 3)

true

Work = (4 3 3)+ (2 2 0)

= (6 5 3)

finish [3] = true< P2, P3, P1>

The system is in a safe state since the sequence <P2, P3, P,> satisfies safety criteria.

(i)Procers P1 requests (1, 1,0) check that Request < = available (1, 1, 0) < = (2, 3, 0) = true

Available = Available – Requestsi

Allocationi = Allocationi + Requesti

Needi = Needi – Requesti

Available = (2 3 0)- (1, 1, 0)

= (1, 2, 0)

Allocationi = (2 2 3) + (l, 1,0)

= (3,3,3)

Needi = (1,4, 5)-(1,1,0)

= (0, 3, 5)

Work = (1, 2, 0)

finish (i) = false for i = 1 to 3

finish [1] = false

(0, 3, 5) < = (1, 2, 0)

finish [3] = false

(2, 2, 0) < = (1, 2, 0)

The system is in unsafe state so the request cannot be granted.

(2)Proces P3 requests (0, 1, 0)

(0, 1, 0) < = (2, 3, 0)

true

Available = (2, 3, 0) – (0, 1, 0)

= (2,2,0)

Allocation3 = (1, 2, 4) + (0, 1, 0)

= (1,3,4)

Need3 = (2, 2, 0)-(0, 1, 0)

= (2, 1, 0)

Work = (2, 2, 0)

finish [i] false for i = 1 to 3.

finish [1] = false

(1, 4, 5) < = (2, 2, 0)

false

finish [2] = fabe

(2, 3, 0) < = (2, 2, 0)

finish [3] = false

(2, 1,0) < = (2, 2, 0)

true finish [3] = true

Work = (3, 2, 0) + (1, 2, 4)

= (4, 4, 4) < P3

finish [1] = false

(1, 4, 5) < =(4, 4, 4)

false

The system is in a safe state since the sequence <P3, P2, P12> satisfies Safety Criteria.

[3]P2 requests (0, 1, 0)

(0,1,0) < =(2,3,0)

true

Available = (2, 3, 0) – (0, 1, 0)

= (2, 2, 0)

Allocation2 = (2, 0, 3) + (0, 1, 0)

= (2, 1, 3)

Need2 = (2, 3, 0) – (0, 1, 0)

= (2, 2, 0)

Work = (2, 2, 0)

finish [i] = false i = 1 to 3

finish [ 1 ] = false

(1,4, 5) < = (2, 2, 0)

False

finish [2] = false

(2, 2, 0) < = (2, 2, 0)

true

Work = (2, 2, 0) + (2, 0, 3)

= (4, 2, 3)< P2

finish [2] = true

finish [3] = false

(2, 2, 0) < = (4, 2, 3)<P2,P3,P1>

∴The system is in safe state

About this essay:

If you use part of this page in your own work, you need to provide a citation, as follows:

Essay Sauce, Exploring Processes, Schedulers & Context Switches with These Concepts. Available from:<https://www.essaysauce.com/sample-essays/2016-2-8-1454935493/> [Accessed 12-05-26].

These Sample essays have been submitted to us by students in order to help you with your studies.

* This essay may have been previously published on EssaySauce.com and/or Essay.uk.com at an earlier date than indicated.