Please disable adblock to view this page.

← Go home

Shell Script and Process Scheduling Algorithms


October 29, 2016
Published By : Pratik Kataria
Categorised in:



Interface between user application or user and kernel (operating system)
The shell reads a command line from its standard input and interprets it according to a fixed set of rules.
The standard input and standard output file descriptors for the login shell are usually the terminal on which the user logged in
If the shell recognizes the input string as a built-in command (for example, commands cd, for, while and others), it executes the command internally without creating new processes

Types of Shell

Bourne shell (sh)
C shell (csh)
Korn shell (ksh)
Functions of shell:

  • Acts as command interpreter
  • Acts as command itself
  • Used as a programming languages

What is a Shell Script?

A Text File
With Instructions
In the simplest terms, a shell script is a file containing a series of commands.
The shell reads this file and carries out the commands as though they have been entered directly on the command line.

$ vi first
#My first shell script
echo “Knowledge is Power”



First-Come, First-Served (FCFS) Scheduling

Schedule the processes according to their arrival order, with no preemption
Process: P1 P2 P3 P4
CPU burst time: 7 4 1 4

P1 P2 P3 P4
7   11   12  16
Waiting Time: 0 7 11 12
Average Waiting time: 7.5 (assuming all processes arrive almost together)

Shortest Remaining Time Next (SRTN) Scheduling

The next process to schedule, is selected on the basis of the shortest remaining execution time (Preemptive).
Non-preemptive version of SRTN is called Shortest Job First (SJF).
Example SRTN (preemptive):
Process:        P1 P2 P3 P4
Arrival Time: 0 2 4 5
CPU burst time: 7 4 1 4

P1 P2 P3 P2 P4 P1
2   4    5    7   11  16
Waiting Time: 9 1 0 2
Average Waiting time: 3

Example SJF (Non-preemptive):
Process: P1 P2 P3 P4
Arrival Time: 0 2 4 5
CPU burst time: 7 4 1 4

P1 P3 P2 P4
7    8   12 16
Waiting Time: 0 6 3 7
Average Waiting time: 4

Time-Slice Scheduling (Round-Robin, RR)

Processor time is divided into slice or quanta, which is allocated to the requestor processes. After that, process is preempted and added to the end of the ready queue.
Process: P1 P2 P3 P4
CPU burst time: 7 4 1 4

P1 P2 P3 P4 P1
4   8    9   13  16
Waiting Time: 9 4 8 9 (assuming time slice=4 and all processes arrive almost
Average Waiting time: 7.5

Priority-Based Preemptive Scheduling (Event-Driven, ED)

Each process is assigned a priority level.
The scheduler always chooses the highest-priority ready process.
Initial values are assigned by the user or the system at process creation time
ED scheduling schedules highest-priority ready process whenever an event occurs
Problem: Starvation of low priority processes
Solution: Aging: Gradually increasing process priority as process spends certain amount of time in the computer system

Multiple-Level Queues (MLQ) Scheduling

Workload is classified according to its characteristics.
Separate process queues are maintained by different schedulers.
Each queue has its own scheduling policy.