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

Basics of Operating Systems: Drnmpatel Associate Professor Computer Engineering Department BVM Engineering College

This document provides an overview of the basics of operating systems. It outlines the course objectives, which are to impart knowledge of operating systems from user and design perspectives. The course outcomes include understanding OS concepts like processes and scheduling, virtual memory management, file systems, protection and security mechanisms. It lists some common operating system textbooks as references. It then discusses the history of operating systems from first to third generation systems and the evolution of features like multiprocessing, time-sharing, and user interaction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views

Basics of Operating Systems: Drnmpatel Associate Professor Computer Engineering Department BVM Engineering College

This document provides an overview of the basics of operating systems. It outlines the course objectives, which are to impart knowledge of operating systems from user and design perspectives. The course outcomes include understanding OS concepts like processes and scheduling, virtual memory management, file systems, protection and security mechanisms. It lists some common operating system textbooks as references. It then discusses the history of operating systems from first to third generation systems and the evolution of features like multiprocessing, time-sharing, and user interaction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 63

Basics of Operating Systems

Dr N M Patel
Associate Professor
Computer Engineering Department
BVM Engineering College
Operating systems
Course Objective:
• To impart knowledge of operating system from user and design
perspectives
Course Outcomes (COs): After learning the course students will be able to
• 1. Understand various Operating Systems concepts such as process, system
calls, multiprocessing, race and dead-locks etc.
• 2. Analyze various scheduling algorithms
• 3. Apprehend virtual memory management, and compare various paging
and segmentation schemes.
• 4. Analyze file systems from user and design perspective.
• 5. Analyze protection and security mechanisms of OS
• 6. Experiment with low level implantation of OS concepts, at lab and mini-
projects level.
Operating systems

• List of References:
• 1. Andrew S. Tanenbaum, “Modern Operating
Systems”, Prentice Hall International
• 2. Silberschatz and Galvin, “Operating System
Concepts”, John Willey and Sons
• 3. William Stallings,“Operating Systems”
Prentice Hall of India
• 4. D.M.Dhamdhere, “Operating Systems”, Tata
McGraw Hill
Why os is required?

Modern computer system consists of one or more


processors, some main memory, disks, keyboard,
a display, a network interfaces and other I/O devices.
Writing programs that keep track of all these components
and use them correctly and optimally is an difficult job.

For this reason, computers are equipped with a layer of


software called the OS, whose job is to manage all these
devices and provide user programs with a simple interface
to the hardware.

An operating system (OS) is system software that manages


computer hardware and software resources and provides
common services for computer programs.
Computer with OS can be viewed as set of layers. Most computers
have two modes of operation: kernel mode and user mode. The
operating system, the most fundamental piece of software,
runs in kernel mode (also called supervisor mode). complete
access to all the hardware and can execute any instruction the
machine is capable of executing. The rest of the software runs in
user mode, in which only a subset of the machine instructions is
available.
Functions of os
Two basic functions
1)Os as an extended machine: It hide the hardware complexity
&provide simple interface with the hardware.It present the user with the
equivalent of an extended machine that is easier to program than the
underlying hardware.

-Abstraction:disk contains a collection of named files

One of the major tasks of the operating system is to hide the


hardware and present programs (and theirprogrammers) with
nice, clean, elegant, consistent, abstractions to work with instead.
2)Resource manager: Provide an
orderly and controlled allocation of the
processors, memories, and I/O devices
among the programs competing for
them
Windows,
Linux,
Android,
Mac,
When we switch on machine what happens?
Two perspective : User and design
Two important concepts
Process
File
Process
Is an instance of program in execution
Each process has its address space : list of memory
locations which it can read and write
The address space contain the executable program, data and
stack. Also it has set of registers including PC ,SP , other
required resources and all other information needed to run
the program.
Every process has unique id called PID
Process table : all the information about each process is
stored in process table, which is an array(or linked list) of
structures, one for each process in existence.
System call related to process e.g. fork, execl, wait,
exit, brk,…
IPC
Command to know about running process : ps, top,…
Every person authorized to use a system is assigned a
UID and GID by the system administrator. User who
create process become owner of that process. A child
process has same UID of its parent
One UID called superuser in UNIX has special power
and may violate many of the protection rules.
Environment to run process : provided by Shell
running on top of os
Common shells for Linux
ash : a small shell
bash : bourne again shell. The default
shell for Red Hat Linux
ksh, tcsh and zsh

$chsh -l
Files
User perspective
How they are named and organized
Hierarchical File System
Process and file hierarchies both are organized as trees
Process hierarchies are not very deep, short-lived ( few
minutes), ownership and protection
Directory Structure
/

bin boot home etc usr dev lib

c
user1 user2 user3
a l
t s p p
r r Desktop
Director
o o
y
g g s
r r t File
m m a
Directory : As a way of
1 2 r
grouping files together
t
File system
• Every file can be specified by giving its path name from the top
of directory hierarchy, the root directory
• Two types of path : absolute and relative
• Every process has current directory
• System call related to files : open,read,write, dup, lseek, fcntl,…
• Mounting files : attach other file system with root file system
• Special files : devices are treated as files, block and character,
pipe
• Security : nine bit protection code
• For directory x indicates search permission
OS

Goals of an operating system:


Execute user programs and make
solving user problems easier.

Convenience

Efficiency
History of operating systems
Os Evolved through the years because enhancement in
semiconductor technology, evolved new hardware
OS closely tied to the architecture of the computers on which
they run
First digital computer was designed by Charles Babbage. It was
purely mechanical
First generation : vacuum tubes, used for numerical
calculations such as tables of sines, cosines and log
All programming was done in absolute machine language. No
OS. Wiring up plug boards to control the machine’s basic
functions
Second generation : transistor
Known as mainframes. Used for scientific and engineering
calculations such as solving the partial differential equations
Given the high cost of the equipment, it is not surprising that people
quickly looked for ways to reduce the wasted time. The solution generally
adopted was the batch system. Batch operating system : FMS(Fortran
monitor system) and IBSYS (IBM os for 7094)
Batch OS : in form of monitor program
Software that controls the sequence of events
Batch jobs together. (i.e., a program or set of programs), Hence
the operating system in this case had to just transfer control
from one job to another in a sequential manner
Program branches back to monitor when finished
Limitations : separate machine for I/O and computation
Current job paused to wait for a tape or other I/O operation ,
CPU simply sat idle until the I/O finished(scientific calculation
: I/O is infrequent but Commercial data processing, The I/O
wait can be 80 to 90% of total time)
Third generation : ICS &Multiprogramming OS:
e.g. IBM 360, 370,4300,3080,3090..
Multiple jobs are in memory
When one job needs to wait for I/O, the processor can switch to the
other job. Enough job could be held in memory at once the CPU could
be busy nearly 100% of the time
The operating system now has additional functionalities of selecting
jobs from the disk to be brought into the main memory(This is done by
the job scheduler ) and selecting one of the jobs in the main memory to
be given to the CPU( CPU scheduler)
Multiprogramming OS
Decision has to be made as to where to place the jobs
in the main memory. Hence memory management was
added as a functionality of the operating system. I/O
devices also have to be allocated to processes. Hence
I/O management was included as a functionality to the
operating system.
Spooling : Simultaneous peripheral operation on line)
Limitation : no user interaction
Limitation: no use interaction

Multiprogrammed systems provide an environment in which the


various system resources (for example, CPU, memory, and
peripheral devices) are utilized effectively, but they do not provide
for user interaction with the computer system.

. Hence, a new system was developed called the time-


sharing systems. These time-sharing systems are basically
an extension of multiprogramming systems and are called
multitasking systems. In time-sharing system the CPU executes
multiple jobs by switching among them but the switches occur so
frequently that users can interact with each program while it is
running
Third generation : Minicomputer &Time sharing Os
Using multiprogramming to handle multiple interactive jobs
Processor’s time is shared among multiple users
Multiple users simultaneously access the system through
terminals
Memory management with swapping required
Since many users are using the computer, each user will have
his/her own files and these files have to be placed in the
secondary storage device / disks. Hence, file systems were
included as a part of operating systems
Objective: Minimize response time
Bell lab, MIT and GE together developed MULTICS
(Multiplexed information and computing Service)
Ken Thompson developed UNIX at Bell lab
Two major version : System V and BSD (Berkely software
distribution) from the university of California at Berkeley
Linus Torvalds developed LINUX
Time sharing Os
It is possible to have many processes of a particular user
or different users to run concurrently. At a particular time,
only one process can use the CPU. When one process is
waiting for I/O, another process may use the CPU and
vice versa. This may not be felt by the users using the
computer. Thus concurrent execution of processes is
possible.
When many processes execute concurrently, they may
have to communicate among themselves or may have to
share common variables or data structures. Hence job
synchronization and communication are needed.
Similarly, when processes execute concurrently and
share resources of the computer, it is possible that
deadlocks may occur. Hence the operating system must
have the capability to handle deadlocks.
Personal systems

Fourth Generation : When personal computers were introduced, there


was a need for an operating system for this new type of computer.
During this era, single-user operating systems such as DOS (Disk
Operating System) were introduced.
Goal : user convenience along with resource utilization
Windows 95, 98 (16bit)
Windows NT (32 bit), Windows NT 5.0(Windows 2000)
Unix for personal computer, support windowing system called X
windows , basic windows management. Often a complete GUI, such as
Gnome or KDE, is available to run on top of X11, giving UNIX a look
and feel something like the Macintosh or Microsoft Windows.
Unix/Linux is multiuser, timesharing, multitasking
Multi processor system: Tightly coupled and loosely coupled
The advantages of multiprocessor systems are increased
throughput, economy of scale and increased reliability
Tightly coupled: The need for more speed and efficiency led to
the design of parallel systems: multiple CPUs on the same
machine. Each CPU can be used to serve one program or a part
of a program, which means that many tasks can be accomplished
in parallel instead of serially. The operating systems required for
this are more complex than those that support single CPUs
Loosely coupled : Multi computer system
Two os : Network and distributed os.
Network os : Communication facility, user is aware about
existence of multiple computers and can log in to remote
machines and copy files from one machine to another. Each
machine run its own local operating system and has its own local
user
Distributed systems

Distributed os is one that appear to its users as a traditional


uniprocessor system even though it is actually composed of
multiple processors. Transparency is main goal
e.g. framework Hadoop

Real-time systems

A real-time system is expected to do a task within a specific


time constraint. They are used with real-time applications,
which monitor, respond to or control external processes or
environments. Hard and soft Qnx, VxWorks, RTLimux
Embedded OS : palmtop and embedded systems
Size, memory and power make them special
e.g. palm os, Windows CE
The Fifth Generation (1990–Present): Mobile Computers
Handheld systems include PDAs, cellular phones etc. The main
issues with these systems are that they have a small size, small
amount of memory, include slow processors, and feature small
display screens. Examples of handheld operating systems are
Android, Apple:iOS, Symbian (Samsung, Sony Ericsson, Motorola,
and especially Nokia.etc.)
Smart card OS
The smallest os run on smart card which are credit card size device
containing CPU chip
They have severe processing power and memory constraints. They
handle single function such as electronics payment
Some smart cards are Java oriented. This means that the ROM on the smart
card holds an interpreter for the Java Virtual Machine (JVM). Java applets
(small programs) are downloaded to the card and are interpreted by the JVM
interpreter.
Some of these cards can handle multiple Java applets at the same time,
leading to multiprogramming and the need to schedule them. Resource
management and protection also become an issue when two or more applets
are present at the same time. These issues must be handled by the (usually
extremely primitive) operating system present on the card.

Fifth Generation : massive parallism, super computer, support AI, Machine


learning and deep learning
System call

• Interface between process and operating


system
• Actual mechanisms of issuing a system call are
highly machine dependent and often must be
expressed in assembly code
• A procedure library is provided to make
system calls from C programs and often from
other languages as Fortran….
• If the system call cannot be carried out return
-1 and error number is put in global variable
errno
System calls are performed in a series of steps
Linux operating system

main()
{
char m[20]=“hello\n”;
asm(“mov $4,%eax”);
asm(“mov $1,”ebx”);
asm(“mov $m,”%ecx”);
asm(“mov $7,%edx”);
Asm(“int $128”);
POSIX

• POSIX has about 100 procedure calls


• Mapping of POSIX procedure calls onto
system calls is not one to one. However most
of the POSIX procedures do invoke system
calls
The POSIX standard specifies a number
of procedures that a conformant system must supply, but
it does not specify whether they are system calls, library
calls, or something else.
If a procedure can be carried out without invoking a
system call (i.e., without trapping to the kernel), it will
usually be done in user space for reasons of
performance.
However, most of the POSIX procedures do invoke
system calls, usually with one procedure mapping
directly onto one system call.
In a few cases, especially where several required procedures
are only minor variations of one another, one system call
handles more than one library call
#define TRUE 1
while (TRUE) { /* repeat forever */
type prompt( ); /* display prompt on the screen */
read command(command, parameters); /* read input from terminal */
if (for k( ) != 0){ /* fork off child process */
/* Parent code. */
waitpid( parameters); /* wait for child to exit */
} else {
/* Child code. */
execve(command, parameters, 0); /* execute command */
}
}
Figure 1-19. A stripped-down shell. Throughout this book, TRUE is
assumed to
be defined as 1.
Win32 API
• Windows and UNIX differ in a fundamental way in their respective
programming models.
• A UNIX program consists of code that does something or other, making system
calls to have certain services performed
windows program is normally event driven Main program waits for some event
to happen, then calls a procedure to handle it.
• Microsoft has defined a set of procedures called the Win32 API (Application
Programming Interface) that programmers are expected to use to get
operating system services
• By decoupling the API interface from the actual system calls, Microsoft retains
the ability to change the actual system calls in time (even from release to
release) without invalidating existing programs.
Win32 has a huge number of calls for managing the GUI
Windows does not have a process hierarchy so there is no concept of a parent and
child process
Win32 interface does not have links to files, mounted file systems, security or
signals
Win32 API calls & corresponding
Unix calls
Design structures
Monolithic systems
• In the monolithic approach the entire operating system runs as a single
program in kernel mode. The operating system is written as a collection of
procedures, linked together into a single large executable binary program.
• Os is written as a collection of procedures each of which can call any of the
other ones whenever it needs to
• OS occupy single address space. To construct the actual object program of
the OS, one first compiles all the individual procedures or files containing
the procedures and then binds them all together into a single object file using
the linker
• Advantage : efficient Disadvantage : any part of OS fail, entire OS fail e.g.
Unix, Linux
• Little structure exists : The services (system
calls) provided by the operating system are
requested by putting the parameters in a well-
defined place (e.g., on the stack) and then
executing a trap instruction. This instruction
switches the machine from user mode to kernel
mode and transfers control to the operating
system
This organization suggests a basic structure for the
operating system:
1. A main program that invokes the requested service
procedure.
2. A set of service procedures that carry out the system
calls.
3. A set of utility procedures that help the service
procedures.
Design structures

In this model, for each system call there is one service


procedure that takes care of it and executes it. The utility
procedures do things that are needed by several service
procedures, such as fetching data from user programs.
Design structure
Layered systems
Os is designed as a hierarchy of layers, each one
constructed upon the one below it.
Each layer can be think as object, which has its
own data and functions.
Advantage : debugging is easy, modularity
Disadvantage : careful definition of layers, less
efficient
The first os : THE system, 6 layers
Design Structures
Design structures
Virtual machines
How to make Time sharing (multitasking) os
1. Mutiprogramming
2. Extended machine : with a more convenient interface then
the bare hardware
Virtual machine runs on the bare hardware and does the
multiprogramming, providing not one but several virtual
machines to the next layer up
By completely separating the functions of multiprogramming and
providing an extended machine, each of the pieces can be much
simple, flexible and easier to maintain
Because each virtual machine is identical to the true hardware, each one can
run any operating system that will run directly on the bare hardware.
Different virtual machines can, and frequently do, run different operating
systems. On the original IBM VM/370 system, some ran OS/360 or one of the
other large batch or transaction-processing operating systems, while others ran
a single-user, interactive system called CMS (Conversational Monitor System)
for interactive timesharing users. The latter was popular with programmers.
Virtual machine

Another use of virtualization is for end users who want to


be able to run two or more operating systems at the same
time, say Windows and Linux, because some
of their favorite application packages run on one and
some run on the other

e.g. VMWare, Xen, KVM (for the Linux kernel), VirtualBox


(by Oracle), and Hyper-V (by Microsoft).
Design Structures
Virtual machine
The idea of virtual machine is heavily used nowadays in a different
context: running old MS-DOS programs on a PENTUM ( or 32 bit
intel CPU) by providing a virtual 8086 mode on the Pentium. In
this mode the machine acts like an 8086 including 16 bit
addressing with a 1MB limit
However when a program tries to trap to the os to make a system
call or tries to do protected I/O directly a trap to the virtual
machine monitor occur
Two variant : MS-DOS itself is loaded into the virtual address
space. In second approach virtual machine monitor just caches the
first trap and does the I/O itself since its knows all the MS-DOS sy
tem calls . It only emulates MS-DOS correctly and not other OS
e.g. Virtual box
Design structures

• JVM: Java virtual machine


Compile produces code for JVM which is executed by
JVM interpreter
Solving system compatibility problem
e.g. windows applications run on sun microsystems
Design structures
Exokernels
In virtual machine each user process gets an exact copy of the actual computer
Researchers at MIT have built a system that gives each user a clone of the
actual computer but with subset of the resources i.e. one machine might get
blocks 0 to 1023, the next one might get 1024 to 2047 and so on
Exokernel is program running in kernel mode whose job is to allocates
resources to virtual machines and then check attempts to use them to make sure
no machine is trying to use somebody else’s resources
Each user level virtual machine can run its own os, except that each one is
restricted to using only the resources it has asked for and been allocated
Advantages : it saves a layer of mapping
In earlier approach each virtual machine think that it has its own disk, with
blocks running from 0 to some maximum, so VMM has to keep table
With exokernel this remapping is not needed. The exokernel need only keep
track of which virtual machine has been assigned which resource
Design structures

Microkernel ( Client-server model)


A trend in modern OS is to take the idea of moving code up into higher layers
even further and remove as possible from kernel mode leaving a minimal
microkernel
The usual approach is to implement most of the OS in user processes. To
request a service, such as reading a block of a file a user process (known as
client) sends the request to a server process which then does the work and
sends back the answer
The basic idea behind the microkernel design is to achieve high reliability
by splitting the operating system up into small, well-defined modules, only
one of which—the microkernel—runs in kernel mode and the rest run as
relatively powerless ordinary user processes.
In particular, by running each device driver and file system as a separate
user process, a bug in one of these can crash that component, but cannot
crash the entire system. Thus a bug in the audio driver will cause the
sound to be garbled or stop, but will not crash the computer.
In contrast, in a monolithic system with all the drivers in the kernel, a
buggy audio driver can easily reference an invalid memory address and
bring the system to a grinding halt instantly.
Microkernel
A few of the better- known microkernels include Integrity, K42,
L4, PikeOS, QNX, Symbian, and
MINIX 3.
One interesting server is the reincarnation server, whose job is to
check if the other servers and drivers are functioning correctly. In
the event that a faulty one is detected, it is automatically replaced
without any user intervention. In this way, the system is self healing
and can achieve high reliability.
Design structures
• Microkerenl
• Kernel handle the communication between clients and servers, handling
interrupts, I/O and minimal process and memory management
Advantages
1. Kernel is thin so manageable and ease of extending the os because new
services are added to user space and do not required modification of the
kernel
2. OS services in from of processes so if one fail other may continue to give
service so will not usually bring the whole machine down
3. Its adaptability to use in distributed systems. If a client communicates with
a server by sending messages the client need not to know whether message
is handle locally in its machine or whether it was sent across a network to
a server on a remove machine
4. It is easier to port from one hardware to another
5. Policy and mechanism can be separted
Disadvantages : less efficient because frequent mode change required
e.g. QNX, Windows NT, Windows 2000
Client-Server
• As far as the client is concerned, the same thing happens in
both cases: requests are sent and replies come back. Thus the
client-server model is an abstraction that can be used for a
single machine or for a network of machines
Architecture of Unix/Linux
Kernel

Buffer
cache
Windows NT
Questions

1.A portable operating system is one that can be ported from


one system architecture to another without any modification.
Explain why it is infeasible to build an operating system that is
completely portable. Describe two high-level layers that you will
have in designing an operating system that is highly portable.
2.What is the key difference between a trap and an interrupt?
3.Number of UNIX system calls have no Win32 API equivalents.
What are the consequences for a programmer of converting a
UNIX program to run under Windows?
Every system architecture has its own set of instructions that it can
execute. Thus a Pentium cannot execute SPARC programs and a
SPARC cannot execute Pentium programs. Also, different
architectures differ in bus architecture used (such as VME, ISA,
PCI, MCA, SBus, ...) as well as the word size of the
CPU (usually 32 or 64 bit).
Because of these differences in hardware, it is not feasible to build
an operating system that is completely portable. A highly portable
operating system will consist of two high-level layers---a machine
dependent layer and a machine independent layer. The machine-
dependent layer addresses the specifics of the hardware, and must
be implemented separately for every architecture. This layer
provides a uniform interface on which the machine-independent
layer is built. The machine-independent layer has to
be implemented only once. To be highly portable, the size of the
machine dependent layer must be kept as small as possible.
Answer
• A trap instruction switches the execution mode of a CPU from
the user mode to the kernel mode. This instruction allows a
user program to invoke functions in the operating system
kernel.
• A trap is caused by the program and is synchronous with it. If
the program is run again and again, the trap will always occur
at exactly the same position in the instruction stream. An
interrupt is caused by an external event and its timing is not
reproducible.
• Several UNIX calls have no counterpart in the Win32 API:
• Link: a Win32 program cannot refer to a file by an alternative
name or see it in more than one directory.
• Mount and umount: a Windows program cannot make
assumptions about standard path names because on systems
with multiple disk drives the drive name part of the path may
be different.
• Chmod: Windows uses access control lists
• Kill: Windows programmers cannot kill a misbehaving
program that is not cooperating.

You might also like