Download - COSC 4740
![Page 1: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/1.jpg)
COSC 4740
Chapter 2
Operating System Structures
![Page 2: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/2.jpg)
O/S Components
• Process management• I/O management• Main Memory management• File & Storage Management• Networking/Communications• Protection and Error Detection• User interface
– Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch Command Interpreter
![Page 3: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/3.jpg)
A View of Operating System Services
![Page 4: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/4.jpg)
Process Management
• Process (or job): A program or a fraction of a program that is loaded in main memory and executing. – We do not need the entire program code at once.
To process an instruction, CPU fetches and executes one instruction of a process after another in the main memory.
![Page 5: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/5.jpg)
Tasks of Process Managemento Create, load, execute, suspend, resume, and
terminate processeso Switch system among multiple processes in the main
memory (process scheduling)o Provides communication mechanisms so that
processes can send (or receive) data to (or from) each other (process communication).
o Control concurrent* access to shared data to keep shared data consistent (process synchronization).
o Allocate/de-allocate resources properly to prevent or avoid deadlock situation**
![Page 6: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/6.jpg)
I/O Management
• Motivations: o Provide the abstract level of H/W devices and keep the
details from applications to ensure proper use of devices, to prevent errors, and to provide users with convenient and efficient programming environment.
• Tasks of I/O Management of OS: o Hide the details of H/W deviceso Manage main memory for the devices using cache, buffer,
and spoolingo Maintain and provide device driver interfaces
![Page 7: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/7.jpg)
Main Memory management
Process must be mapped to physical addresses and loaded into main memory to be executed.
• Motivations:o Increase system performance by increasing “hit” ratio
(e.g., optimum: when CPU read data or instruction, it is in the main memory always)
o Maximize memory utilization• Tasks of Main Memory Management of OS:
o Keep track of which memory area is used by whom.o Allocate/de-allocated memory as need
![Page 8: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/8.jpg)
File & Storage Management
• Motivation: o Almost everything is stored in secondary storage.
Therefore, secondary storage access must be efficient (i.e., performance) and convenient (i.e., easy to program I/O function in application level)
o Important data are duplicated and/or stored in ternary storage.
![Page 9: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/9.jpg)
• Tasks of File Managemento Create, manipulate, delete files and directories
• Tasks of Storage Managemento Allocate, de-allocate, and defrag blocks[1]
o Bad block markingo Scheduling for multiple I/O request to optimize
the performance
![Page 10: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/10.jpg)
Networking/Communications
• Allow communications between computers (more important for Client/Server OS and Distributed OS).
• Communications may be via shared memory or through message passing (packets moved by the OS)
![Page 11: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/11.jpg)
Protection and Error Detection
• Protection– Hardware resources, Kernel code, processes, files, and
data from erroneous programs and malicious programs. • Error detection
– May occur in the CPU and memory hardware, in I/O devices, and in user program
– For each type of error, OS should take the appropriate action to ensure correct and consistent computing
– Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system
![Page 12: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/12.jpg)
Command Interpreter
• Command Interpreter is one of the most important system programs[1]. Because almost every OS provide system programs, some people argue that command interpreter is a part of OS.
• Motivation:o Allow human users to interact with OSo Provide convenient programming environment to users
![Page 13: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/13.jpg)
• Tasks:o Execute a user command by calling one or more number
of underlying system programs or system calls
• Examples:o Windows DOS command windowo Bash of Unix/Linuxo CSHELL of Unix/Linux
![Page 14: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/14.jpg)
System Calls• Programming interface to the services provided by the OS
– Typically written in a high-level language (C or C++)– Mostly accessed by programs via a high-level Application Program
Interface (API) rather than direct system call use• Three most common APIs are Win32 API for Windows, POSIX
API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM)
• Why use APIs rather than system calls?
![Page 15: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/15.jpg)
Example of System Calls
• System call sequence to copy the contents of one file to another file
![Page 16: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/16.jpg)
Example of Standard API• Consider the ReadFile() function in the• Win32 API—a function for reading from a file
• A description of the parameters passed to ReadFile()– HANDLE file—the file to be read– LPVOID buffer—a buffer where the data will be read into and written from– DWORD bytesToRead—the number of bytes to be read into the buffer– LPDWORD bytesRead—the number of bytes read during the last read– LPOVERLAPPED ovl—indicates if overlapped I/O is being used
![Page 17: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/17.jpg)
Types of System Calls
• Process control• File management• Device management• Information maintenance• Communications
![Page 18: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/18.jpg)
System Call Implementation• Typically, a number associated with each system call
– System-call interface maintains a table indexed according to these numbers
• The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values
• The caller need know nothing about how the system call is implemented– Just needs to obey API and understand what OS will do as a
result call– Most details of OS interface hidden from programmer by API
• Managed by run-time support library (set of functions built into libraries included with compiler)
![Page 19: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/19.jpg)
API – System Call – OS Relationship
![Page 20: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/20.jpg)
Standard C Library Example
• C program invoking printf() library call, which calls write() system call
![Page 21: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/21.jpg)
API vs. System Call summary
• An API is application programming interface– This are a set of standard functions that the
program calls. – This API then call the specific System call for that
specific O/S
• A system call is specific to an O/S– The system call for an O/S may be different
between versions• Different parameters, even different names.
![Page 22: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/22.jpg)
Operating System Design and Implementation
• Design and Implementation of OS not “solvable”, but some approaches have proven successful
• Internal structure of different Operating Systems can vary widely
• Start by defining goals and specifications • User goals and System goals
– User goals – operating system should be convenient to use, easy to learn, reliable, safe, and fast
– System goals – operating system should be easy to design, implement, and maintain, as well as flexible, reliable, error-free, and efficient
![Page 23: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/23.jpg)
Operating System Design and Implementation (Cont.)
• Important principle to separatePolicy: What will be done? Mechanism: How to do it?
• Mechanisms determine how to do something, policies decide what will be done– The separation of policy from mechanism is a very
important principle, it allows maximum flexibility if policy decisions are to be changed later
![Page 24: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/24.jpg)
Simple Structure
• MS-DOS – written to provide the most functionality in the least space– Not divided into modules– Although MS-DOS has some structure, its
interfaces and levels of functionality are not well separated
![Page 25: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/25.jpg)
MS-DOS Layer Structure
![Page 26: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/26.jpg)
Monolithic (The big mass) O/S• OS is simply a collection of functions, which can call
any other ones when needed.• One very big OS including everything (system calls, system
programs, every managers, device drivers, etc)• Entire OS resides in main memory
• Pros:• High performance• Easy to implement
• Cons:• Difficult to debug, modify, and upgrade• Poor security, protection, and stability of OS
![Page 27: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/27.jpg)
Layered Approach • still large single program
but internally broken up into layers providing different functionalities.
• Information hiding between layers Increased security and protection
• Easy to debug, test, and modify OS
• If one layer stops working, entire system will stop
• Example:System CallsMemory ManagementProcess SchedulingI/O ManagementDevice Drivers
• Mapping overhead between layers
• Difficult to categorize into layers
![Page 28: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/28.jpg)
Layered Operating System
![Page 29: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/29.jpg)
UNIX
• UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring. The UNIX OS consists of two separable parts– Systems programs– The kernel
• Consists of everything below the system-call interface and above the physical hardware
• Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level
![Page 30: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/30.jpg)
UNIX System Structure
![Page 31: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/31.jpg)
Microkernel System Structure • Moves as much from the kernel into “user” space• OS is made up of several separated/independent modules
– kernel, FS, MM, etc and only kernel resides in main memory. • Kernel calls other modules as needed to perform certain
tasks.– Benefits:
• Easier to extend a microkernel• Easier to port the operating system to new architectures• More reliable (less code is running in kernel mode)• More secure
– Detriments:• Performance overhead of user space to kernel space communication
![Page 32: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/32.jpg)
Mac OS X Structure
![Page 33: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/33.jpg)
Modules
• Most modern operating systems implement kernel modules– Uses object-oriented approach– Each core component is separate– Each talks to the others over known interfaces– Each is loadable as needed within the kernel
• Overall, similar to layers but with more flexible
![Page 34: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/34.jpg)
Solaris Modular Approach
![Page 35: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/35.jpg)
Virtual Machines
• A virtual machine takes the layered approach to its logical conclusion. It treats hardware and the operating system kernel as though they were all hardware
• A virtual machine provides an interface identical to the underlying bare hardware
• The operating system creates the illusion of multiple processes, each executing on its own processor with its own (virtual) memory
![Page 36: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/36.jpg)
Virtual Machines Cont. • Allow multiple different OS to run on a single
machine. VM gives an illusion that the machine is at entire disposal of OS by providing each OS an abstract machine.
o Pros:o Solve machine-OS-software compatibility issues.o Stable and Good for OS development and testing (If one
OS fails, the other OS can continue to run)o Cons:
o Complex to develop/implement– Poor performance (abstract layer, mapping overhead
between layers, …)
![Page 37: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/37.jpg)
Virtual Machines History and Benefits
• First appeared commercially in IBM mainframes in 1972• Fundamentally, multiple execution environments (different
operating systems) can share the same hardware• Protect from each other• Some sharing of file can be permitted, controlled• Commutate with each other, other physical systems via
networking• Useful for development, testing• Consolidation of many low-resource use systems onto fewer
busier systems• “Open Virtual Machine Format”, standard format of virtual
machines, allows a VM to run within many different virtual machine (host) platforms
![Page 38: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/38.jpg)
Virtual Machines (Cont.)
(a) Nonvirtual machine (b) virtual machine
Non-virtual Machine Virtual Machine
![Page 39: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/39.jpg)
VMware Architecture
![Page 40: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/40.jpg)
The Java Virtual Machine
![Page 41: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/41.jpg)
Client-Server
• OS consists of servers, clients, and kernel. Kernel is very tiny and handles only the communication between the clients and servers. Both clients and servers run in user mode.o Pros:
o Stable (If a server fails, the OS can still operate)o Small kernel
o Cons:o Complex to develop/implement (servers run in user mode and can
access resources through kernel)o Security problem because servers reside in user space.
![Page 42: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/42.jpg)
Back to Design Goals• Efficiency and Convenience• Keep kernel adequately small
o Too much functionality in kernel low flexibility at higher level
o Too little functionality in kernel low functional support at higher level
• Maximize the utilization, performance, and functionality of the underlying H/W resourceso OS design is affected by H/W propertieso OS design is affected by the type of system to design (e.g.,
Multiprogramming, Multi-tasking, Real-time, Distributed, .etc)
![Page 43: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/43.jpg)
System Generation
• We should configure OS for the underlying hardware when we install it (i.e., installing OS)
• Approaches:• Modify the source code of OS and recompile it on
the target machine• Pros: small OS size, We can tune the details for the H/W• Cons: Very difficult, less flexible for H/W upgrade
![Page 44: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/44.jpg)
System Generation Cont.
• Provide many pre-compiled modules (e.g., five different memory manager object files). When we install OS, select certain object modules and link them together accordingly.• Pros: easy to configure, flexible for H/W upgrade• Cons: big OS size, We cannot tune the very details
for the H/W
![Page 45: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/45.jpg)
System Boot• Operating system must be made available
to hardware so hardware can start it– Small piece of code – bootstrap loader, locates
the kernel, loads it into memory, and starts it– Sometimes two-step process where boot block
at fixed location loads bootstrap loader– When power initialized on system, execution
starts at a fixed memory location• Firmware used to hold initial boot code
![Page 46: COSC 4740](https://reader034.vdocuments.us/reader034/viewer/2022051316/56813a32550346895da21cb0/html5/thumbnails/46.jpg)
QA&