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

Operating Systems and Linux I

The document discusses the key functions and components of operating systems. It describes how operating systems manage hardware resources like the CPU, memory, and I/O devices to provide services to users. It also discusses important OS concepts like interrupts, memory hierarchy with caches, and how operating systems have evolved from simple batch processing to more advanced multiprogramming and time-sharing systems to improve resource utilization and user experience.

Uploaded by

divyarai12345
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Operating Systems and Linux I

The document discusses the key functions and components of operating systems. It describes how operating systems manage hardware resources like the CPU, memory, and I/O devices to provide services to users. It also discusses important OS concepts like interrupts, memory hierarchy with caches, and how operating systems have evolved from simple batch processing to more advanced multiprogramming and time-sharing systems to improve resource utilization and user experience.

Uploaded by

divyarai12345
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 41

Operating Systems and Linux

Partha Sarathi Dasgupta

MIS Group
Indian Institute of Management Calcutta
What does an Operating System do?

An Operating System exploits the hardware resources of one


or more processors to provide a set of services to system users.

An Operating System also manages secondary memory and


input/output devices on behalf of its users.
Structural Elements of a Computer
Processor: Controls the operation of the computer and its
Data Processing functions.. A single processor is often termed as
the Central Processing Unit.

Main memory: Stores data and programs. This memory is


typically volatile. Contents of disk memory are retained even
when the computer is shut down.

I/O modules: Moves data between the computer and its external
environment, such as disks, data communication equipments,
and terminals.

System bus: Provides for communication between processors,


main memory, and I/O modules.
Structural Elements of a Computer: Schematic view
CPU
0

MAR 1
PC
2
MBR Instruction
IR Instruction
I/O AR Instruction
I/O BR
Execution

Data
Data
Data
Data
n -2
Buffers n -1
Input-Output Module
Interrupts

A mechanism by which other modules (I/O, memory) may


interrupt the normal sequencing of the processor
Interrupts help to improve processor utilization.
Classes of interrupts:

Program: generated by some condition that occurs as a result of an


instruction execution, such as arithmetic overflow, division by zero,
attempt to execute an illegal machine instruction, and reference outside
a users allowed memory space.
Timer: Generated by a timer within the processor. This allows the
operating system to perform certain functions regularly.
I/O: Generated by an I/O controller, to signal normal completion of an
operation or to signal a variety of error conditions.
H/W failure: Generated by a failure, such as power, etc.
An Example
A processor has two programs P1 and P2 to execute:
P1 is simply reading data from memory and writing the data into
the disk. P2 is doing only calculations.

Processor may begin P1 first, issue a write command to the


external device, and then proceed with P2.

Two cases:
Writing to disk initiated by P1 might finish before P2 completes
calculations.

P2 completes calculations before the disk writing initiated by


P1 finishes.

What are the consequences of these two cases?


Memory Hierarchy

Registers

Cache

Main Memory

Magnetic disk, CD-ROM, CD-RW


DVD-RW, DVD-RAM

Magnetic tape
Cache

a portion of the main memory that can be used as a buffer


temporarily holds data that are to br read out to disk
Caches improve the performance in two ways:
Disk writes are clustered.
instead of having many small transfers of data, few large
transfers are possible.
some data meant for write-out (from disk) may be directly
accessed from the cache very fast.
Operating System
It is a program that
controls the execution of application programs
acts as an interface between applications and computer hardware
manages the resources associated with a computer

Objectives of an O.S.
Convenience of use of the computer

Efficient use of the computing resources


Should be such that it can permit effective development, testing and
introduction of new system functions without affecting he service.
Operating System as an Interface

Application Programs End user

Utilities

Programmer

Operating System

Computer Hardware OS System


Designer
Operating System Services

Program Development variety of services and utilities such as


Editors and debuggers. They are usually referred to as application program
development tools.

Program Execution involves a number of steps, such as loading


Instruction and data in the main memory, initialisation of I/O devices and
files, and other resources to be allocated. OS handles the scheduling.

Access to I/O devices Each I/O device has its own set of
Instructions and control signals. O.S. hides these details to provide a
common interface to the user/programmer.
Operating System Services
Controlled access to files- nature of I/O device (disk drive, tape
drive) and structure of the data stored in the files in the storage medium. In
the case of multiple users accessing the processor concurrently, proper
protection mechanisms have to be used.

System access- For shared or public systems, the O.S. controls access
to the system as a whole and to specific system resources. Access system
provides protection of resources, and data from unauthorised users, and
resolves resource conflicts

Error detection and response Variety of errors may occur in


computer system. Responses may range from program termination, retrial of
the same operation, or reporting error to the application.

Accounting collecting usage statistics, CPU usages, monitor


performance, etc.
Evolution of Operating Systems

Serial Processing
From 1940s to mid-1950s
Programmer interacted with the hardware
Programs in machine code were loaded via the input device (card
reader)
In case of any error, they were indicated with lights

Associated problems:

Scheduling: Hardcopy sigh-up sheet for reserving time


User could reserve for 45 mins and finish in 30 mins => wastage of time
User may not be able to finish in scheduled time
Evolution of Operating Systems
Simple Batch Processing
for maximizing machine utilisation
batch O.S. used
a piece of software called the monitor used
monitor reads in jobs one at a time from the input device
as a job is read in, control is passed to the current job; control returns
back to the monitor when the job is finished
results of a job are sent to an output device such as the printer
Processor is executing the instructions from those of the monitor
Processor will then execute the instruction of the user program until it
encounters an ending or error condition
instructions for the monitor are contained in the JCL
monitor

Interr Device Job


Control User
upt drivers seque
language Program
proce ncing
interpreter Area
ssing
Modes of a user program

A user program executes in user mode, in which certain areas


of memory are protected from the users use, and

certain instructions may not be executed.

monitor executes in a system mode, or a kernel mode, in


which privileged instructions may be executed and protected
memory segments accessed.

Batch O.S. machine time alternates between monitor and the


user programs.

Effect: some memory given to the monitor, and some of the


machine time is consumed by the monitor.
An example of System Utilization

Read one record from a file = 19 s

Execute 100 instructions = 2 s

Write one record to a file = 19 s


---------

TOTAL 40 s

Percent CPU utilization = 2/40 = 0.005 = 0.5%


An example of Multiprogramming

P1 Run Wait Run Wait

Wait Run Wait Run Wait


P2

P3 Wait Run Wait Run Wait

P1, P2, P3 Run Run Run Wait Run Run Run Wait

Any Advantage?
Multiprogramming/Multitasking: Some Figures

Multiprogramming Operating systems are more complex


Memory management
Scheduling
Uniprogramming Multiprogramming

Processor use 20% 40%


Memory use 33% 67%
Disk use 33% 67%
Printer use 33% 67%
Elapsed time 30 min 15 min
Throughput 6 jobs/hr 12 jobs/hr
Mean response time 18 min 10 min

Effect of Multiprogramming on Resource Utilization


Time-Sharing Systems
For some jobs, e.g., for transaction processing jobs, it is
desirable that users may interact directly with the computer
Processor time is shared among multiple users through
time sharing
multiple users simultaneously access the system through
terminals, with the O.S. interleaving the execution of each
user program in time quanta.
For n users actively requesting service at one time (for
instance, all editing files), each user will only see on the
average 1/n of the effective computer capacity (approx.)
Given the slow human reaction time, response time is
similar to that on a dedicated machine
Multiprogramming and Time-Sharing

Multiprogramming maximises CPU utilization


Time-sharing minimizes user response rime

What about the Throughput?


Major theoretical advances in development of O.S.

Processes

Memory management

Information protection and security

Scheduling and resource management

System structure
Processes

A process is

a program in state of execution

An instance of a program running on a computer

The entity that can be assigned to and executed on a processor

A unit of activity characterised by a single sequential thread of


execution, a current state, and an associated set of system
resources
Why Processes need to be scheduled?
Improper synchronization: for example, a process that initiates an I/O read
must wait until the data are available in a buffer. This requires signal from
some other process.

Mutual exclusion: multiple users might try to access a shared resource


concurrently, e.g., editing the same file at the same time. Mutual exclusion
mechanism required.

Non-determinate program operation: Results of a program normally


depend on the input to that program only. When programs share memory, and
their execution is interleaved by the processor, they may interfere with each
other. Order of program execution may affect the execution of a particular
program.

Deadlock: It is possible for two or more programs to be hung up waiting for


each other.
Parts of a Process
Components of a process
An executable program
Associated data required by the program (variable, work space, buffer,
etc.)
Execution context: internal data used by O.S. to supervise a process =
process state.

Process list Main memory

Program code

Program code
context

context
data

data
Process Control Block
Identifier: A unique integer associated with a process
State : A currently executing process is in running state
Priority : Priority level relative to other processes
Program counter : Address of the next instruction of the
program to be executed.
Memory pointers: pointers to the program code and data
associated with the process, and any shared memory blocks
Context data: Data in the registers in the processor during
process execution.
I/O status information: outstanding I/O requests, I/O devices
allocated to the process, a list of files is use by the process, etc.
Accounting information: amount of processor time, etc.
Key responsibilities of Resource management

O.S. manages the resources of a computer system


Factors for scheduling policy:
Fairness: processes competing for a resource should be given fair
chance of resource access
Differential responsiveness: O.S. should make allocation and
scheduling decisions to meet total set of requirements, and in a dynamic
manner. E.g., if a process is waiting for an I/O device, O.S. may schedule
that process as soon as the device is free.
Efficiency: Maximize throughput, minimize response time, and
accommodate as many concurrent users as possible.
Virtual Memory

A facility that allows programs to address memory from a logical


viewpoint
Disregards the amount of physical memory actually available
Meets the requirements of multiple user processes to reside
simultaneously in main memory without any interference
(Demand) Paging system and Page faults
Address of a word of a program = page number + offset within page
Pages vs Blocks mapping
Problem of contiguous block assignment

File A File B File C

10 20 30

Is the contiguous block allocation OK?


Why use Linux/Unix?
System is written in a high-level language => easy to read,
understand, change and port to other machines.

Simpler user interface or user services

Provides simple routines to write complex programs/develop


utilities

Hierarchical file system for easy maintenance

Consistent format for files (byte streams) making application


development easier

Simple, consistent interface to peripheral devices


UNIX Architecture

Kernel
Application Programs
Shell
UNIX commands and
libraries
Utilities
System call
interface

bash

H/W

who
Kernel

wc

vi
Traditional Unix Kernel
User programs
Libraries
User level
Kernel level

System call interface

File subsystem IPC

Buffer cache Process control


scheduler
subsystem
Character Block Memory
management
Device drivers

Hardware control
Kernel level
Hardware level
Hardware
Some Basic Characteristics of Linux

Multi-user System

Multiprogramming/Multitasking system

Uses Time Sharing

Access rights for Files and Processes

Uses File and Process hierarchies


Linux File System

Characteristics:

Hierarchical structure
Consistent treatment of file data
Ability to create, modify and delete files
Dynamic growth of files
Protection of file data
Treating peripheral devices (terminals, tapes, etc.) as files
Linux File System Layout (RedHat)
Directory Structure of Linux File System

Directory Content
Common programs, shared by the system, the system administrator and
/bin
the users.
The startup files and the kernel, vmlinuz. In recent distributions also grub
/boot data. Grub is the GRand Unified Boot loader and is an attempt to get rid
of the many different boot-loaders we know today.
Contains references to all the CPU peripheral hardware, which are
/dev
represented as files with special properties.
Most important system configuration files are in /etc, this directory
/etc
contains data similar to those in the Control Panel in Windows
/home Home directories of the common users.
/initrd (on some distributions) Information for booting. Do not remove!
Library files, includes files for all kinds of programs needed by the
/lib
system and the users.
Directory Structure of Linux File System
Directory Content

Every partition has a lost+found in its upper directory. Files that were saved during
/lost+found
failures are here.
/misc For miscellaneous purposes.
/mnt Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.
/net Standard mount point for entire remote file systems
/opt Typically contains extra and third party software.
A virtual file system containing information about system resources. More information
/proc about the meaning of the files in proc is obtained by entering the command man proc in
a terminal window.
The administrative user's home directory. Mind the difference between /, the root
/root
directory and /root, the home directory of the root user.
/sbin Programs for use by the system and the system administrator.
/tmp Temporary space for use by the system.
/usr Programs, libraries, documentation etc. for all user-related programs.
Storage for all variable files and temporary files created by users, such as log files, the
/var mail queue, the print spooler area, space for temporary storage of files downloaded from
the Internet, or to keep an image of a CD before burning it.
Mounting of file systems

etc usr
usr

tom harry
Types of files in a Linux System

"On a UNIX system, everything is a file; if something is not a file, it is a process."

Regular files : they contain normal data, for example text files, executable files
or programs, input for or output from a program and so on.
Directories: files that are lists of other files.
Special files: Devices treated as files, used for input and output. They exist
in /dev.
Links: a system to make a file or directory visible in multiple parts of the
system's file tree.
(Domain) sockets: a special file type, similar to TCP/IP sockets, providing
inter-process networking protected by the file system's access control.

Named pipes: act more or less like sockets and form a way for processes to
communicate with each other, without using network socket semantics.
Permissions of a file

Read

Write

execute
Listing files in a Linux System
The -l option to ls displays the file type, using the first character of each input line:

psdg/Documents> ls l

total 8
-rw-rw-r-- 1 psdg faculty 31744 Feb 21 17:56 samplefile1.doc
lrw-rw-r-- 1 psdg faculty 41472 Feb 21 17:56 samplefile2
drwxrwxr-x 2 psdg faculty 4096 Feb 25 11:50 os-course/
crw-rw-r-- 1 psdg faculty 41472 Feb 21 17:56 /dev/tty00

Symbol Meaning
- Regular file
d Directory
l Link
c Special file
s Socket
p Named pipe
User Accounts

login nmes

passwords

user id

group id

Home directory

You might also like