Professional Documents
Culture Documents
Nov 2001
OS Concepts
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
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
Acknowledgements
Unix Internals, The New Frontiers - Uresh Vahalia The Design Of The Unix Operating System Maurice Bach Operating Systems - William Stallings
OS Concepts
Computer Architecture
CPU(s) Memory I/O devices and interrupts Clock
OS Concepts
OS Concepts
The definition, purpose and scope of an Operating System
OS Concepts
OS Concepts
The definition, purpose and scope of an Operating System
Scope: Is :
- to manage the system resources
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
OS Concepts
The Basic functionality of OS and layering of OS components
OS Concepts
OS Concepts
The Basic functionality of OS and layering of OS components
OS Concepts
OS Concepts
The Basic functionality of OS and layering of OS components
OS Concepts
OS Concepts
The Basic functionality of OS and layering of OS components
OS Concepts
OS Concepts
Evolution of Operating Systems
Serial processing Simple batch processing Multi-programmed batch processing Time-shared systems SMP (Symmetric Multi-processing)
OS Concepts
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
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
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
OS Concepts
Process Creation & Termination
OS Concepts
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
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
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
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
OS Concepts
OS Concepts
Virtual Memory systems Process's (virtual) memory space 000+-------+ | | | | | | | | | | | | | | MAX+------+
OS Concepts
OS Concepts
Virtual Memory systems
OS Concepts
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.
OS Concepts
OS Concepts
File systems (local/network)
OS Concepts
OS Concepts
File systems (local/network)
OS Concepts
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
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
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
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
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
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
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
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
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
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
OS Concepts
Device drivers, Peripheral control & Communication
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
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
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
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
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
OS Concepts
Systems programming
OS Concepts
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
OS Concepts
Writing Portable code What is portable code ?
Code that is designed to be ported across various platforms, operating systems, middleware etc.
OS Concepts
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
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
OS Concepts
OS and its role in networking:
drivers for the data link layer (layer #2 of ISO/OSI) most often drivers for n/w and transport layers
OS Concepts
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
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
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
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