Operating Systems: Bea May M. Belarmino Joselle A. Banocnoc Khryss Leanne B. Omnes
Operating Systems: Bea May M. Belarmino Joselle A. Banocnoc Khryss Leanne B. Omnes
Module 8: Concurrency
Introduction 4
Learning Outcomes 4
Lesson 1: Principles of Concurrency 155
Lesson 2: Principles of Deadlock 156
Lesson 3: Deadlock Prevention, Avoidance, and Detection 159
Lesson 4: Mutual Exclusion 162
Lesson 5: Semaphores 164
Lesson 6: Monitor 165
Assessment Task 167
Summary 168
Module 9: Scheduling
Introduction 169
Learning Outcomes 169
Lesson 1: Types of Processor Scheduling 170
Lesson 2: Scheduling Algorithms 172
Lesson 3: Multiprocessor and Multicore 177
Lesson 4: Real-Time Scheduling 179
Assessment Task 180
Summary 181
iii
MODULE 8
CONCURRENCY
Introduction
This module will tackle about the concurrency about the principles of
concurrency, principles of deadlock, deadlock prevention, avoidance, and detection,
mutual exclusion, semaphores, monitor.
Learning Outcomes
i
v
Lesson 1. Principles of Concurrency
Concurrency is the interleaving of processes in time to give the
appearance of simultaneous execution (Staillings, 2015, p. 202).
In the figure 7.1, there are times that a certain data in a database is being
shared with clients and it is usually processed in the server. A server can handle
processes and can handle storage of processed data (Staillings, 2015, p. 202).
15
5
Locating programming errors can be difficult, because the contexts in which
errors occur cannot always be reproduced easily (Staillings, 2015, p. 202).
These are the conditions for encountering a deadlock (Staillings, 2015, p. 270):
1. Mutual exclusion. Only one process may use a resource at a time. No process
may access a resource unit that has been allocated to another process.
2. Hold and wait. A process may hold allocated resources while awaiting
assignment of other resources.
Figure 8.5 Hold and Wait
Source: Stallings (2015, p.
53)
it.
Figure 8.6 No Preemption
Source: Stallings (2015, p.
53)
4. Circular wait. A closed chain of processes exists, such that each process holds
at least one resource needed by the next process.
From the four conditions of deadlock, Numbers 1, 2 and 3 are only
stating that there is a possibility of a deadlock.
If the process has encountered Number 4, it is already in the state of
deadlock.
Figure 8.7 Circular
Wait Source: Stallings
(2015, p. 53)
Example (Staillings, 2015, p. 270):
Mutual exclusion: Microsoft Word and Microsoft Excel processes wants to
use, at the same time, the printer.
Hold and Wait: The OS hold some memory allocation and waiting for some
process to use it, so that, the OS could let go for other process.
No Preemption: The Windows 10 OS installs the updates, which includes the
latest patch and hotfix for better storage management.
Circular Wait: Window Explorer wants accessing the storage device and
currently holding the RAM. Microsoft Access want to access the RAM and
currently holding the processor. Operating System wants to access the
processor but currently holds the storage device. In short, they are in a
circular wait, waiting for a resource to be open in order to proceed
processing.
Circular Wait: The circular wait condition can be prevented by defining a linear
ordering of resource types.
Deadlock Avoidance
It allows the three necessary conditions but makes practical choices to assure that
the deadlock point is never reached. There are two options (Staillings, 2015, p.
271):
Process Initiation Denial. Setting up needed/maximum resources preprocess prior to
its execution.
Resource Allocation Denial. Banker’s Algorithm
Examples of such resources include files, I/O devices such as printers, and
shared data structures.
semWait (x);
<critical code section>
semSignal (x);
If more than this number try to enter the critical section, the excess processes
will be blocked until some processes exit (Stallings, 2015, p. 221).
Monitors are significantly easier to validate than “bare” semaphores for at least two reasons
(Stallings, 2015, p. 230):
All synchronization code is confined to the monitor; and
Once the monitor is correct, any number of processes sharing the
resource will operate correctly.
Table 8.1 Difference between Semaphores and Monitors (Stalings, 2015 p. 229-233)
Assessment Task
I. ESSAY (80 points) Perform what is being asked. Type your answer on EDMODO or
Google Classroom.
References
Learning Outcomes
169
Lesson 1. Types of Processor Scheduling
The aim of processor scheduling is to assign processes to be executed by
the processor, in a way that meets system objectives (Stallings, 2015, p. 398):
Scheduling affects the performance of the system because it determines which
processes will wait and which will progress (Stallings, 2015, p. 398).
Types of Scheduling
Long-Term - This determines which programs are admitted to the system
for processing. Once admitted, a job or user program becomes a process and is
added to the queue for the short-term scheduler (Stallings, 2015, p. 399):
17
0
Non-Preemptive Scheduling
Non-Preemptive Scheduling means once a process starts its execution or the
CPU is processing a specific process it cannot be halted or in other words we cannot
preempt (take control) the CPU to some other process (Stallings, 2015, p. 406).
A computer system implementing this cannot support the execution of
process in a multi task fashion. It executes all the processes in a sequential manner
(Stallings, 2015, p. 406).
Preemptive Scheduling
Preemptive Scheduling means once a process started its execution, the
currently running process can be paused for a short period of time to handle some
other process of higher priority, it means we can preempt the control of CPU from
one process to another if required (Stallings, 2015, p. 406).
A computer system implementing this supports multi-tasking as it gives the
user impression that the user can work on multiple processes (Stallings, 2015, p.
406).
The technique of estimating the next value in a series by taking the weighted
average of the current measured value and the previous estimate is sometimes called
aging. It is applicable to many situations where a prediction must be made based on
previous values. Aging is especially easy to implement when a = 1/2. All that is
needed is to add the new value to the current estimate and divide the sum by 2 (by
shifting it right 1 bit) (Tanenbaum, 2015, 162).
Figure 9.4 Scheduling SPN
Source: Tanenbaum (2015, p.
Short Remaining Time First 162)
In priority scheduling, the waiting time and turnaround time of higher priorities
are minimized. However, this may lead to starvation, where in low‐priority processes
may wait indefinitely in the ready queue. To solve this, a method called aging can be
used where in the priority of a process gradually increases the longer it stays in the
ready queue Tanenbaum (2017, p. 162).
Materials:
VB.net) Procedures:
This module discussed the scheduling about the types of processor scheduling,
scheduling algorithm, multiprocessor and multicore, scheduling, and real time scheduling.
References
Stallings, (2015). Operating Systems Internals And Design Principles 8th Edition
.Pearson Education
Tanenbaum, A. (2015). Modern Operating Systems 4th Edition. Pearson Education
McHoes, A. and Flynn, I. (2014). Understanding operating system, 7th edition.
Cengage Learning
Haldar S. and Aravind A., (2010). Operating Systems. India: Dorling Kindersley
MODULE 10
USING THE vi EDITOR IN LINUX
Introduction
This module introduces the vi editor and describes the vi commands. These
commands include the input commands, the positioning commands, and the editing
commands (Tutorialspoint, 2013).
Learning Outcomes
The visual display or vieditor is an interactive editor that you can use
tocreate and modify text files. You can use the vieditor when the desktop
environment window system is not available. The vieditor is also the only text
editor that you can use to edit certain system files without changing the
permissions of the files.
All text editing with the vieditor takes place in a buffer. You can eitherwrite
the changes to the disk, or discard them (Tutorialspoint, 2013).
182
The viEditor Modes of Operation
The vieditor is a command-line editor that has three basic modes ofoperation:
Command mode
Edit mode
1. Command Mode
The command mode is the default mode for the vi editor. In this mode,
you can perform commands to delete, change, copy, and move text. You
can also position the cursor, search for text strings, and exit the
vieditor(Tutorialspoint, 2013).
2. Edit Mode
You can enter text into a file in the edit mode. The vieditor
interpretseverything you type in the edit mode as text. To enter the edit
mode, perform the commands:
You can use advanced editing commands in the last line mode. To
accessthe last line mode, enter a colon (:) while in the command mode.
The colon places your cursor at the bottom line of the screen
(Tutorialspoint, 2013).
18
4
mode, you can save the file and quit the vieditor.
vi
vi filename
vi optionsfilename
If the system crashes while you are editing a file, you can use the
-roption to recover the file.
$ vi -r filename
The file opens so that you can edit it. You can then save the file and exitthe vieditor.
$ vi -R filename
You can use the vi editor to view files in the read-only mode, or you can edit
files in the vi editor using the vi editing commands. When using the vieditor, you can
move the cursor using certain key sequences (Tutorialspoint, 2013).
The viewcommand enables you to view files in the read-only mode. It invokes the vieditor
with the read-only option. Although most of the vicommands are available, you cannot
save changes to the file (Tutorialspoint, 2013).
viewfilename
$ cd
$ viewdante
The dantefile appears. Perform the: q command to exit the file and the
vieditor. q
Command Function
:rfilename Inserts text from another file into the current file
Note – The vieditor is case sensitive. Use the appropriate case for
theinput commands.
history option
$ history
…
date
cd/etc
touch dat1
dat2 ps -ef
history
The history command is an alias built into the Korn shell that enables you to display
previously- executed commands.
To display the current command and the four commands preceding it, perform the following
command:
$ history -4
...
107 date
108 cd /etc
109 touch dat1 dat2
110 ps -ef
111 history
The r command is an alias built into the Korn shell that enables you to repeat a
command (Tutorialspoint, 2013).
To repeat the cal command by using the r command, perform the following
command:
$ cal December
2004
S M Tu W Th F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
$r
cal
December 2004
S M Tu W Th F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Assessment Task
4. Write the command to navigate to your home directory from your current
working directory using the appropriate special metacharacter.
II. To use directory and file commands, complete the following steps. Write
the commands that you would use to perform each task in the space
provided.
1. Return to your home directory (if you need to), and list the contents.
Option Description
-i
Includes the contents of a directory, including
the contents of all subdirectories, when you
copy a directory
6. From your home directory, create a directory called practice1.
In this chapter, we will understand how the vi Editor works in Unix. There are
many ways to edit files in Unix. Editing files using the screen-oriented text editor vi
is one of the best ways. This editor enables you to edit lines in context with other
lines in the file.
An improved version of the vi editor which is called the VIM has also been
made available now. Here, VIM stands for Vi IMproved.
vi is generally considered the de facto standard in Unix editors because −
It's usually available on all the flavors of Unix system.
Its implementations are very similar across the board.
It requires very few resources.
It is more user-friendly than other editors such as the ed or the ex.
You can use the vi editor to edit an existing file or to create a new file from scratch.
You can also use this editor to just read a text file.
References
MAY 2021