Chap 4 - Operating System
Chap 4 - Operating System
OPERATING SYSTEMS
Class: Comp. Sc A/L By:
By NDANG George
Modern general-purpose computers, including personal computers and mainframes, have an operating
system to run other programs, such as application software. An operating system act as an intermediary
between the user of a computer and computer hardware. The purpose of an operating system is to provide an
environment in which a user can execute programs in a convenient and efficient manner. Operating systems
are present on almost all modern devices described as computers, from personal computers to mainframes,
as well as mobile computers such as PDAs and mobile phones.
CHAPTER OBJECTIVES
This chapter aims:
- Define Operating system, functions, history and Evolution
- To describe the services an operating system provides to users, processes, and other systems.
- To discuss the various ways of structuring an operating system.
- To explain some Operating system concept such as system call, kernel mode, deadlock, paging,
segmentation …
- To describe in detail some functions of operating systems such as process management, memory
management, device management, …
- To describe some examples of today’s operating systems and contrast Linux & Windows operating system
Table of Contents
An operating system provides services to programs and to the users of those programs.
- It provides programs an environment for the execution of programs. (interface)
- It provides users, services to execute the programs in a convenient manner. (services)
III. SERVICES OF AN OS
The common service provided by the operating system is listed below.
1. Program execution: Operating system loads a program into memory and executes the program. The
program must be able to end its execution, either normally or abnormally.
2. I/O operation: I/O means any file or any specific I/O device. Program may require any I/O device while
running. So operating system must provide the means to do I/O.
3. File system manipulation: Program needs to read a file or write a file. The operating system gives the
permission to the program for operation on file.
4. Communications: Data transfer between two processes is required for some time. The both processes are
on the one computer or on different computer but connected through computer network. Communication may
be implemented by two methods: Shared memory and Message passing.
5. Error detection: The operating system constantly needs to be aware of possible errors in CPU, in I/O
devices or in memory hardware. It should take the appropriate action to ensure correct and consistent
computing.
6. Resource allocation: Operating system manages different types of resources require special allocation
code, i.e. main memory, CPU cycles and file storage.
IV- EVOLUTION OF OS
Historically operating systems have been tightly related to the computer architecture. Operating systems have
evolved through a number of distinct phases or generations which corresponds roughly to the decades.
V.1 OS Kernel
The lowest level of any operating system is its kernel. This is the first layer of software loaded into memory
when a system boots or starts up. The kernel provides access to various common core services to all other
system and application programs. These services include, but are not limited to: disk access, memory
management, task scheduling, and access to other hardware devices.
V.5 Interrupt
An interrupt in an interruption in the normal execution of the program. When the CPU is interrupt, then it stops
its current activities like execution of the program. And transfer the control to interrupting device to check the
interrupt. The three types of interrupts are
• software interrupts or trap (syscall) - invoked by software
• external interrupts - invoked by external devices
• exceptions - invoked by the processor when errors occur
Interrupt Handling
VI.4 Multi-user
A multi-user operating system allows many different users to take advantage of the computer's resources
simultaneously. Unix, VMS and mainframe operating systems, such as MVS, are examples of multi-user
operating systems.
VI.5 Multiprocessing OS
Multiprogramming OS have two or more processors for a single running process. Processing takes place in
parallel and is also called parallel processing. Each processor works on different parts of the same task, or, on
two or more different tasks. Linux, UNIX and Windows 7 are examples of multiprocessing OS.
2) Round Robin:
Here each process is provided a fix time to execute called quantum or slice time. After this time has
elapsed, the process is preempted and added to the end of the ready queue and other process executes for
given time period. Context switching is used to save states of preempted processes.
Example: Quantum = 3
Process Arrival time Bust Time Wait Time : Service Time - Arrival Time
P0 0 5 (0-0) + (12-3) = 9
P1 1 3 (3-1) = 2
P2 2 8 (6-2) + (14-9) + (19-17) = 11
P3 3 6 (9-3) + (17-12) = 11
The idea behind the SJF algorithm is to pick the quickest fastest little job that needs to be done, get it out
of the way first, and then pick the next smallest fastest job to do next. (Technically this algorithm picks a
process based on the next shortest CPU burst, not the overall process time.). For example, the Gantt chart
below is based upon the following CPU burst times, (and the assumption that all jobs arrive at the same time.)
Process Arrival time Burst time Service Time Wait Time : Service Time -
Arrival Time
P0 0 5 0 0-0=0
P1 1 3 5 5-1=4
P2 2 8 14 14 - 2 = 12
P3 3 6 8 8-3=5
P3 P2
4) Priority Scheduling
Each process is assigned a priority. Process with highest priority is to be executed first and so on. Processes with
same priority are executed on first come first serve basis. Priority can be decided based on memory requirements,
time requirements or any other resource requirement
P0 P3 P1
5 11
Wait time of each process is following
VIII. DEADLOCK
VIII.1 Definition and examples of deadlock
Let’s consider the situation where there are two utility programs A and B that each want to copy a file from tape
to disk and print the file to printer
- A holds tape and disk, then requests for a printer
- B holds printer, then requests for tape and disk
- A tries to get ownership of the printer, but is told to wait for B to release it.
- B tries to get ownership of the tape, but is told to wait for A to release it.
None of the process will be able to print and the two processes will remain in deadlock.
A deadlock occurs when an every member of a set of processes is waiting for an event that can only be
caused by a member of the set.
NB: The presence of a cycle in a RAG is a necessary and not a sufficient condition for the deadlock to occur. It
IX.1 Relocation
When a process is to be executed, it has to be loaded from the secondary
storage (like hard disk) to the main memory (RAM). This is called
process loading. Since, main memory is limited and other processes also
need it for their execution, an operating system swaps the two processes,
which is called swapping. Once the process is 'swapped out', it is
uncertain to predict when it will be 'swapped in' because of the number
of processes running concurrently
2) Segmentation
By NDANG George Page 15
Topic : OPERATING SYSTEM
Segmentation is a Memory Management technique in which memory is divided into variable sized chunks
which can be allocated to processes. Each chunk is called a segment. A table stores the information about all
such segments and is called Global Descriptor Table (GDT). A GDT entry is called Global Descriptor.
3) Difference between paging and segmentation:-
Paging and segmentation are closed relative to each other but they have following difference.
→ Paging divides the virtual memory in physical memory areas while the segmentation divides it logically.
→ Paging divides the memory in fixed length memory areas while segmentation divides into variable length
memory areas.
→ In segmentation a full logical portion of the process in loaded, but in paging information about page is
loaded.
→ The segments are large length as compare to page.
→ In segmentation memory is divided into segments through software and in paging the memory in divided
through hardware.
A page fault is an interrupt that occurs when a software program attempts to access an invalid page in memory.
A page fault occurs when a program cannot find a page that it’s looking for in the physical memory, which
means that the program would have to access the paging file (which resides on the hard disk) to retrieve the
desired page.
X. FILE MANAGEMENT
File Operations
Any file system provides not only a means to store data organized as files, but a collection of functions
that can be performed on files. Typical operations include the following:
- Create: A new file is defined and positioned within the structure of files.
- Delete: A file is removed from the file structure and destroyed.
- Open: An existing file is declared to be "opened" by a process, allowing the process to
perform functions on the file.
- Close: The file is closed with respect to a process, so that the process no longer may perform
functions on the file, until the process opens the file again.
- Read: A process reads all or a portion of the data in a file.
- Write: A process updates a file, either by adding new data that expands the size of the file or
by changing the values of existing data items in the file.
Directory
Information about files is kept in the directory structure, which is maintained on the disk. A directory
is nothing but a named section of a storage device, such as hard disk, floppy disk. In other words, to
organize file on hard disk or floppy disk, these are divided into various segments (sections), called
directories. You can store any number of files in each directory. The directory helps to organise your
file in an efficient manner.
A file management system is that set of system software that provides services to users and applications in
the use of files. Following objectives for a file management system:
• To meet the data management needs and requirements of the user which include storage of data and
the ability to perform the aforementioned operations.
• To guarantee, to the extent possible, that the data in the file are valid.
• To optimize performance, both from the system point of view in terms of overall throughput.
• To provide I/O support for a variety of storage device types.
• To minimize or eliminate the potential for lost or destroyed data.
• To provide a standardized set of I/O interface routines to use processes.
1) User Authentication
The process of authenticating users can be based on a user's possession like a key or card, user information
like the username and password or user attributes like fingerprints and signature. Among these techniques,
user information is often the first and most significant line of defence in a multiuser system. Unfortunately,
passwords can often be guessed, illegally transferred or exposed. To avoid such situations, a user should keep
the following points in mind:
1) Password should be at least six characters in length.
2) The system should keep track of any event about any attempt to break the password.
3) The system should allow limited number of attempts for submitting a password on a particular system.
4) Password based on dictionary words should be discouraged by the system. Alphanumeric passwords,
such as PASS011, should be used.
2) Backup of Data
To backup is to copy files to a second medium (a disk or tape) as a precaution in case the first medium fails.
One of the cardinal rules in using computers is back up your files regularly. OS provide a feature of backing up
of data, for example, from a disk to another storage device such as a floppy disk or an optical disk. The purpose
of keeping backups is to be able to restore individual files or complete file system in case of data loss.
3) Data encryption
Encryption is the conversion of data (called plaintext) into a form (called a cyphertext) that cannot
be easily understood by unauthorised user. Before being able to understand the content of the data, the receiver
must be in possession of an encryption key used to decrypt the cyphertext.
XIII. EXAMPLES OF OS
XIII.1 Commonly used OS
Some of the commonly used operating systems are discussed below:
1. DOS (Disk Operating System): MS- DOS was the widely used operating system before the introduction
of the Windows operating system. Even now the MS- DOS commands are used for carrying out many jobs like
copying the files, deleting the files etc. The main functions of DOS are to manage files, allocate system
resources according to the requirement. It provides essential features to control hardware devices such a
keyboard, screen, disk drives, printers, modems etc.