You are on page 1of 53

OS Concepts

Nov 2001

OS Concepts

Saturday, February 25, 2012 1

OS Concepts
Table of Contents
1. 2. 3. 4. 5. 6. 7. 8. The definition, purpose and scope of an OS The Basic functionality of OS and layering of OS components The various kinds of Operating Systems Virtual Memory systems Processes, threads and job control File systems (local/network) Process scheduling Memory Management (kernel, user)

OS Concepts

Saturday, February 25, 2012 2

OS Concepts
Table of Contents
9. Interprocess Communication

10. Device drivers, Peripheral control & Communication 11. System calls 12. Systems programming 13. Writing portable code (OS and platform dependencies) 14. OS and its role in Networking 15. Role of OS in Internet and WWW 16. Sysadmin concepts, Operations & Efficient use of system resources

OS Concepts

Saturday, February 25, 2012 3

Acknowledgements
Unix Internals, The New Frontiers - Uresh Vahalia The Design Of The Unix Operating System Maurice Bach Operating Systems - William Stallings

OS Concepts

Saturday, February 25, 2012 4

Computer Architecture
CPU(s) Memory I/O devices and interrupts Clock

OS Concepts

Saturday, February 25, 2012 5

OS Concepts
The definition, purpose and scope of an Operating System

Definition & Purpose:


It's a piece of special software that manages the resources of the system (hardware) and provides a well-defined interface to the user(s) to access the resources to get the user's job done. Typical resources managed by the OS :
CPU(s), memory, I/O and communication devices (discs, tapes, terminals, kb's, mouse, network devices etc) and such.

OS Concepts

Saturday, February 25, 2012 6

OS Concepts
The definition, purpose and scope of an Operating System

Scope: Is :
- to manage the system resources

- to provide services to users to access the resources in a uniform manner

Is not :
- to provide user interface (like a command shell or GUI)

- to do the job of applications (such as DBMS's, systems programming tools, utilities etc etc)

OS Concepts

Saturday, February 25, 2012 7

OS Concepts
The Basic functionality of OS and layering of OS components

The layering of components of a system


All tools, utilities, user apps -------------------------------kernel -------------------------------firmware (or BIOS) -------------------------------hardware

OS Concepts

Saturday, February 25, 2012 8

OS Concepts
The Basic functionality of OS and layering of OS components

The functionality provided by a typical OS


Process management & job control Scheduling File system Memory management Device management (I/O) System access Error detection and Response Accounting

OS Concepts

Saturday, February 25, 2012 9

OS Concepts
The Basic functionality of OS and layering of OS components

Features Multi-programming/processing Multi-user Time-sharing Virtual memory

OS Concepts

Saturday, February 25, 2012 10

OS Concepts
The Basic functionality of OS and layering of OS components

Hierarchy of components within the OS kernel :


Components closest to the firm/hardware (memory manager, interrupt handlers, lower layers of device drivers, clock handler, low-level dispatcher etc) Next level of components (file system, process manager, virtual memory system etc) System calls (closest to the user)

OS Concepts

Saturday, February 25, 2012 11

OS Concepts
Evolution of Operating Systems

Serial processing Simple batch processing Multi-programmed batch processing Time-shared systems SMP (Symmetric Multi-processing)

OS Concepts

Saturday, February 25, 2012 12

OS Concepts
The various kinds of Operating Systems

General-purpose vs Dedicated systems Proprietary vs Open systems Real-time vs non-realtime Systems Systems for Mainframes, mini's & Super-mini's, PC's Scalable vs non-scalable Systems Micro-kernels vs complete systems

OS Concepts

Saturday, February 25, 2012 13

OS Concepts
The various kinds of Operating Systems Essentials of an RTOS :
Pre-emptive kernel and re-entrant device drivers Deterministic response and interrupt latency

Re-entrant kernels :
More than one process could be executing in kernel at the same time

OS Concepts

Saturday, February 25, 2012 14

OS Concepts
Processes, threads and job control

Process - a program in execution Process address spaces - code, data (static, dynamic, stack) Mode of execution - kernel mode, user mode context - process context/kernel context privileges - usually just two levels (user, kernel)

OS Concepts

Saturday, February 25, 2012 15

OS Concepts
Process Creation & Termination

Process Creation reasons


new job, new logon by other processes by the OS for providing a service

Process termination reasons (typical)


normal exit errors : bounds violation, protection violation, arithmetic error, invalid instruction, killed by parent or by system

OS Concepts

Saturday, February 25, 2012 16

OS Concepts
Processes, threads and job control Typical Process States
created Ready Running Blocked (waiting for I/O or system resources) Exit/Zombie

OS Concepts

Saturday, February 25, 2012 17

OS Concepts
Processes, threads and job control Threads (like in Unix, OS/2) :
Individual flows of execution within the context of a process, sharing process's code, global data (static), but having a separate stack (local variables). Sharing of data between threads of the same process - through access synchronization and mutual exclusion (semaphores/locks)

NT Threads :
Synchronization among threads is achieved through sync. objects (process, thread, file, event, event pair, semaphores, timers)
Saturday, February 25, 2012 18

OS Concepts

OS Concepts
Processes, threads and job control Process and Job control
Process groups, association of resources with processes in a group Fore-ground & back-ground processes suspend and resume jobs controlling resources allocated to a job (CPU time, disk space, memory etc)

OS Concepts

Saturday, February 25, 2012 19

OS Concepts
Concurrency principles

Concurrency among processes Process Synchronization Deadlocks & Starvation Mutual exclusion and hardware support (for disabling and enabling interrupts) Critical regions

OS Concepts

Saturday, February 25, 2012 20

OS concepts
Memory Management

Memory Hierarchy
registers, cache, main memory, secondary memory (disks, tapes, optical disks

Requirements of MM
relocation (program linking, loading, partitioning, swapping) protection sharing logical organization physical organization
OS Concepts Saturday, February 25, 2012 21

OS Concepts
Virtual Memory systems

What's virtual Memory ?


That's not real! Rather, it's a memory space presented to the process (the application), parts or whole of which would be mapped to the physical memory available on the system

OS Concepts

Saturday, February 25, 2012 22

OS Concepts
Virtual Memory systems Process's (virtual) memory space 000+-------+ | | | | | | | | | | | | | | MAX+------+

parts of which are mapped to physical memory pages

OS Concepts

Saturday, February 25, 2012 23

OS Concepts
Virtual Memory systems

Process address space :


Each process has its own virtual space not shared with any other process. The kernel has its own address space.

Virtual to Physical page mapping :


The OS keeps per-process virtual-to-physical page mapping in per-process page tables.

OS Concepts

Saturday, February 25, 2012 24

OS Concepts
Virtual Memory systems Demand paging and swapping :
The virtual pages that the process attempts to access are allocated physical pages (demand paging), on demand Swap space : temp. area on disk to kick the physical pages out, when there is memory pressure. When not accessed, they are swapped out, so as to release the physical memory for other processes. Page fetching, replacement policies and cleaning policies are dependent on the system configuration, capacity, response policies and so on.
Saturday, February 25, 2012 25

OS Concepts

OS Concepts
Virtual Memory systems Thrashing
The kernel keeps bringing in pages from swap area only to kick them out to make space for pages needed to be in memory - system is busy doing this rather than any real work.Concept of minimum resident set for a process to run is used in some systems to avoid thrashing.

What's the essential support needed from the h/w to support VM ?


Ability to notify the OS of page faults (you access a (virtual) page and it doesn't have physical memory associated with it).

OS Concepts

Saturday, February 25, 2012 26

OS Concepts
File systems (local/network)

Purpose of a file system :


To provide a facility to the user to store and retrieve data (in the form of files) on/from persistent storage media (disk/tape/floppy etc)

Components of a file system :


Lowest-level - interface with device drivers Next level - space allocation and organization algorithms User-level - system calls to provide file system services (User interface)

OS Concepts

Saturday, February 25, 2012 27

OS Concepts
File systems (local/network)

Data components of a file system


Meta-data like super-block, inode table, directory data etc File data File attributes : size, read/write permissions, creation/access time stamps etc

OS Concepts

Saturday, February 25, 2012 28

OS Concepts
File systems (local/network)

File I/O Synchrous / Asynchrous I/O / Blocking vs Non-blocking I/O Remote/Network file system Same interface on the client side

OS Concepts

Saturday, February 25, 2012 29

OS Concepts
File systems (local/network) Sun's NFS (de facto standard on UNIX as well as non-UNIX systems)
transparent access to remote file systems. Based on client-server model RPC's and network layers provide the underlying functionality in addition to facilities in the local OS to hook in the NFS. Stateless (most important characteristic) server doesn't maintain any state info of client requests all requests are atomic and read/write calls have to pass file offset explicitly crash recovery is simple - if client crashes, server is not affected

OS Concepts

Saturday, February 25, 2012 30

OS Concepts
Process scheduling
This comes into picture only on time-shared systems, multi-processing systems.

Scheduler goals :
Scheduler must judiciously apportion CPU time (and other resources) to all processes, which can be loosely classified as follows : Interactive Batch Real-time

OS Concepts

Saturday, February 25, 2012 31

OS Concepts
Process scheduling Various kinds of scheduling policies :
Shortest Process Next (SPN) First-come First Serve (FCFS) round-robin priority-based dynamically computed priority-based

Unix System V Scheduling - round-robin within each of the priority queues NT scheduling - designed to favour single interactive user with multi-tasking or for running in server mode

OS Concepts

Saturday, February 25, 2012 32

OS Concepts
Process scheduling Priority inversion
Temp priority boost of a lower-priority process to complete the operation and release a system resource for which a higher priority process is waiting

Process accounting
system time, user time, elapsed time CPU usage, disk usage, memory usage

OS Concepts

Saturday, February 25, 2012 33

OS Concepts
Process scheduling Process Scheduling on MP systems
Per-processor data structure containing current process/thread info Per-processor run queue Load sharing Processor affinity Process migration

OS Concepts

Saturday, February 25, 2012 34

OS Concepts
Memory Management (kernel, user)
The kernel must manage all the physical memory for use by other kernel sub-systems as well as user processes. In many operating systems, the kernel at boot time, reserves certain physical memory for its static data and code.

OS Concepts

Saturday, February 25, 2012 35

OS Concepts
Memory Management (kernel, user) All VM systems have a page-level allocator which has usually two clients :
paging system that allocates pages to processes to hold parts of their address space (code, static/dynamic data) kernel memory allocator for allocating sub-page objects at run-time such as process structures, temp buffers to copy system call parameters etc.

OS Concepts

Saturday, February 25, 2012 36

OS Concepts
Interprocess Communication Purpose :
To provide mechanism for two or more related or unrelated processes to communicate with one another (exchange data/info whatever)

Data transfer - from one process to another, of varying size Sharing data - among several participating processes Event notification - such as process termination Resource sharing - among co-operating processes, with their own protocol to safely access/modify shared resources process control - such as what debuggers would need

OS Concepts

Saturday, February 25, 2012 37

OS Concepts
Interprocess Communication Mechanisms available in many UNIX/non-UNIX systems
Shared memory : a chunk of memory (in kernel space) mapped into the address space of the sharing processes. Preferable to use them with semaphores for data integrity. Signals & message queues named and un-named pipes sockets

OS Concepts

Saturday, February 25, 2012 38

OS Concepts
Device drivers, Peripheral control & Communication

How do peripheral devices communicate with the system


Through interrupts; usually there is an interrupt allocation scheme for various types of devices (kb/screen/disks/tapes/network cards etc)

On the software side, device driver developers would write an ISR (Interrupt Service Routine) to service the interrupts raised by the device. This ISR would be registered with the kernel against this device. And this will be part of the device driver module for that device. The device driver usually would export a standard set of API to control and communicate with the device (such as open/read/write etc).

OS Concepts

Saturday, February 25, 2012 39

OS Concepts
Device drivers, Peripheral control & Communication
For devices such as SCSI devices, there usually are two levels of drivers Interface driver (lower-level) to control the SCSI interface card device driver (higher-level) for specific device on the controller card, such as disk or tape. The kernel interacts with the device driver for read/write and other operations, which in turn passes down the command to the interface driver which finally passes it down to the hardware.

OS Concepts

Saturday, February 25, 2012 40

OS Concepts
System calls
The kernel of an OS usually provides a procedural interface to its resources (h/w, s/w) that can be programmatically called by an application program. The interface is usually well-defined and has a uniform style of parameters and return values (with common error number values, standard set of include files etc).

OS Concepts

Saturday, February 25, 2012 41

OS Concepts
System Calls
The standard set of system calls usually includes system calls for:
process management file/directory services user/account management (sysadmin) memory management inter-process communication process control (debuggers) misc

OS Concepts

Saturday, February 25, 2012 42

OS Concepts
System calls
A system call is usually the gateway to enter the kernel. It usually executes in kernel mode but in process context. Thus it will have access to process address space (UNIX systems). If the system call results in the process being blocked (say on a read or write), then that process will be put to sleep; will be woken up when that requested operation is done. System calls in general are privileged and may be expensive.

OS Concepts

Saturday, February 25, 2012 43

OS Concepts
Systems programming

What is systems programming ?


Programming that needs awareness of the system details, resources, the OS- and platform-specific details. Examples are - assembler, compiler, linker, loader, network drivers

OS Concepts

Saturday, February 25, 2012 44

OS Concepts
Systems programming What do you need to know :
The syntax and semantics of various system calls, the hardware architecture and how to access the h/w components (only where needed, such as in device drivers).

OS Concepts

Saturday, February 25, 2012 45

OS Concepts
Writing Portable code What is portable code ?
Code that is designed to be ported across various platforms, operating systems, middleware etc.

Why write portable code ?


Quite often we are required to develop apps for various platforms, not just one. If it's designed and coded to be easily portable, effort for porting it to various other platforms would be minimized and future versions could be moved forward easily.

OS Concepts

Saturday, February 25, 2012 46

OS Concepts
Writing Portable code Examples of writing portable code (choice of lib/sys calls) :
Using stdio functions (such as fopen/fread/fwrite etc) instead of system calls (such as open/close/read/write etc) because they may not be uniformly same across all OS's; but stdio library is standard across all OS's. Designing a package of intermediate layer functions for possible OS/platform-dependent operations (such as reading a char from the keyboard, writing to terminal etc) so that the main app is independent of the OS/platform and can be ported without any changes. Using standard compiler options so that the code can be easily compiled on the chosen platforms without problems.

OS Concepts

Saturday, February 25, 2012 47

OS Concepts
Writing Portable code

Defining and using global data types (using typedef or equivalent directives) to suit your needs rather than assuming the sizes of built-in data types (like int will be 32 bits on all platforms) Using standard bit-level operations provided by the programming language rather than making assumptions about the sizes of various data types and native byte order

OS Concepts

Saturday, February 25, 2012 48

OS Concepts
OS and its role in networking:

What's minimally required to be included in the core OS (kernel) :

drivers for the data link layer (layer #2 of ISO/OSI) most often drivers for n/w and transport layers

OS Concepts

Saturday, February 25, 2012 49

OS Concepts
OS and its role in networking:
How is the interface b/n the kernel and the network components :
Usually the NIC's (network interface cards, such as Ethernet) have a software driver that controls the card and implements the data link layer protocol. They will have a interrupt bit alloated for each of them to get the attention of the system (say, on arrival of a packet). Often the modules that implement the network (eg IP) and transport (eg TCP or UDP) layers are part of the kernel, both for performance reasons as well as for the purpose of being able to serve all processes that need their services, including kernel processes.

OS Concepts

Saturday, February 25, 2012 50

OS Concepts
OS and its role in networking: Typical kernel services expected by network drivers :
memory allocation services for n/w buffers services for timeout services for assigning specific drivers with the hardware they control services for synchronization and mutual exclusion (semaphores and spinlocks and such)

OS Concepts

Saturday, February 25, 2012 51

OS Concepts
OS and its role in Internet and WWW:

Internet and WWW are based on client-server computing paradigm. What servers do we see on the Internet : http ftp email NNTP (Newsgroups) and may be more

OS Concepts

Saturday, February 25, 2012 52

OS Concepts
OS and its role in Internet and WWW: What parameters determine the server's power ?
no. of simultaneous client connections response time for each request main memory and disk space network bandwidth it has access to

While designing and deploying a web-server we need to keep these aspects in mind.

OS Concepts

Saturday, February 25, 2012 53

You might also like