1 Operating Systems and Linux Partha Sarathi Dasgupta MIS Group Indian Institute of Management...

41
1 Operating Systems and Linux Partha Sarathi Dasgupta MIS Group Indian Institute of Management Calcutta
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    224
  • download

    1

Transcript of 1 Operating Systems and Linux Partha Sarathi Dasgupta MIS Group Indian Institute of Management...

1

Operating Systems and Linux

Partha Sarathi Dasgupta

MIS Group

Indian Institute of Management Calcutta

2

• 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.

What does an Operating System do?

3

• 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

4

Structural Elements of a Computer: Schematic view

InstructionInstructionInstruction

DataDataDataData

0

1

2

n -1n -2

Input-Output Module

CPU

PC

IR

Execution

MAR

MBR

I/O AR

I/O BR

Buffers

5

• 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 user’s 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.

Interrupts

6

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?

7

Memory Hierarchy

Registers

Cache

Main Memory

Magnetic disk, CD-ROM, CD-RW

DVD-RW, DVD-RAM

Magnetic tape

8

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.

9

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.

10

Operating System as an Interface

Application Programs

Utilities

Operating System

Computer Hardware

End user

Programmer

OS System Designer

11

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.

12

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.

13

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

14

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

Interrupt

processing

Device drivers

Job sequencing

Control language

interpreter

User Program

Area

monitor

15

Modes of a user program

• A user program executes in user mode, in which certain areas of memory are protected from the user’s 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.

16

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%

17

An example of Multiprogramming

Run Wait Run Wait

Run RunWait Wait

Run RunWait Wait

Wait

Wait

Run Run Run Run Run RunWait Wait

P1

P2

P3

P1, P2, P3

Any Advantage?

18

Multiprogramming/Multitasking: Some Figures

Multiprogramming Operating systems are more complex

• Memory management

• Scheduling

Effect of Multiprogramming on Resource Utilization

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

19

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

20

Multiprogramming and Time-Sharing

• Multiprogramming maximises CPU utilization

• Time-sharing minimizes user response rime

What about the Throughput?

21

Major theoretical advances in development of O.S.

• Processes

• Memory management

• Information protection and security

• Scheduling and resource management

• System structure

22

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

23

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.

24

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.

Main memory

context

data

Program

code

context

Program

code

data

Process list

25

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.

26

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.

27

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

28

Problem of contiguous block assignment

File A File B File C

10 20 30

Is the contiguous block allocation OK?

29

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

30

UNIX Architecture

H/W

Kernel

System call interface

UNIX commands and libraries

Application Programs

wc

vi

who

bash

• Kernel

• Shell

• Utilities

31

Traditional Unix Kernel

Hardware

Hardware control

Kernel levelHardware level

Device drivers

Character Block

Buffer cache

File subsystem

Process control

subsystem

IPC

scheduler

Memory management

System call interface

LibrariesUser programs

Kernel levelUser level

32

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

33

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

34

Linux File System Layout (RedHat)

35

Directory Content

/binCommon programs, shared by the system, the system administrator and the users.

/bootThe startup files and the kernel, vmlinuz. In recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today.

/devContains references to all the CPU peripheral hardware, which are represented as files with special properties.

/etcMost important system configuration files are in /etc, this directory 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!

/libLibrary files, includes files for all kinds of programs needed by the system and the users.

Directory Structure of Linux File System

36

Directory Content

/lost+foundEvery partition has a lost+found in its upper directory. Files that were saved during 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.

/procA virtual file system containing information about system resources. More information about the meaning of the files in proc is obtained by entering the command man proc in a terminal window.

/rootThe administrative user's home directory. Mind the difference between /, the 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.

/varStorage for all variable files and temporary files created by users, such as log files, the 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.

Directory Structure of Linux File System

37

Mounting of file systems

etc usr

tom

usr

harry

38

"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.

Types of files in a Linux System

39

•Read

•Write

•execute

Permissions of a file

40

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.doclrw-rw-r-- 1 psdg faculty 41472 Feb 21 17:56 samplefile2drwxrwxr-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

41

User Accounts

• login nmes

• passwords

• user id

• group id

• Home directory