Chapter 2: Operating-System Structures Prepared by Imtithal Alnour Saeed Objectives • Describing services operating system provides to users and system programs. • Discussing the various ways of structuring an operating system. Prepared by Imtithal Alnour Saeed 2 Chapter 2: Operating-System Structures • • • • • • Operating System Services. User Operating System Interface. System Calls interface. System Programs. Operating System Design and Implementation. Operating System Structure. Prepared by Imtithal Alnour Saeed 3 Operating System Services • There are two sets of operating-system services one provided for users and the other set provided for the system programs – The one set of operating-system services that provides functions helpful to the user: • User interface (UI)- Command-Line (CLI) and Graphics User Interface (GUI), batch interface. • Program execution - The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally • I/O operations- programs require I/O operations. • File-system manipulation - (reading, writing , searching , listing file Information, managing permission, creating and deleting of files and directories). • Processes communications (on the same computer or over a network), via shared memory or by message passing. • Error detection (in CPU, memory hardware, I/O devices or user program), and taking the appropriate action for consistent computing. Prepared by Imtithal Alnour Saeed 4 – E.g. Debugging facilities user and programmer to manage errors. Operating System Services (cont) – Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing • Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to each of them (CPU cycles , main memory, and file storage). • Accounting - To keep track of which users use how much and what kinds of computer resources. • Protection (means concurrent processes should not interfere with each other) • Security for the system from outsiders requires (authentication, authorization..) Prepared by Imtithal Alnour Saeed 5 User Operating System Interface (CLI, GUI) • CLI(Command Line Interface) allows direct command entry – Implementation could be in kernel – Systems program or – Multiple flavors implementation (e.g. shells in UNIX). • GUI (Graphic User Interface) is a user-friendly desktop graphical interface by using mouse, keyboard, and monitor – Icons represent directories(folders), files, programs, actions, etc – GUI invented at Xerox PARC in 1973 then by Apple Macintosh computers in the 1980s. • Hybrid CLI and GUI: Many systems now include both CLI and GUI interfaces – (e.g. Microsoft Windows is GUI with CLI “command” shell, – Apple Mac OS X as “Aqua” GUI interface with UNIX kernel underneath and shells available, – Solaris is CLI with optional GUI interfaces (Java Desktop, KDE). Prepared by Imtithal Alnour Saeed 6 Example CLI in windows (DOS) Prepared by Imtithal Alnour Saeed 7 Example GUI in windows Prepared by Imtithal Alnour Saeed 8 Example GUI in LINUX Prepared by Imtithal Alnour Saeed 9 Example Interface of Android Prepared by Imtithal Alnour Saeed 10 System Calls • System calls (for programmers) are programming interface to the provided by the OS. • Typically written in a high-level language (C or C++). • Managed in two ways by programs of high-level – Application Program Interface (API) or – Direct system call use. • Three most common APIs are – Win32 API for Windows, – POSIX API for POSIX-based systems – Java API for the Java virtual machine (JVM). • Why use APIs rather than system calls? – Portability on any system that supports the same API. – To avoid more details and difficulties working with actual system Prepared by Imtithal Alnour Saeed 11 call. API – System Call – OS Relationship(Example) Prepared by Imtithal Alnour Saeed 12 Standard C Library (Example) • C program invoking printf() library call, which calls write() system call. Prepared by Imtithal Alnour Saeed 13 Types of System Calls • Process control • File management • Device management • Information maintenance • Communications Prepared by Imtithal Alnour Saeed 14 System Programs • System programs is the users’ view of the operating system, not the actual system calls. • Some of them are simply translated from user program to system calls; others are more complex. • System programs used for providing convenient environment for program development and execution. • System programs they can be divided into: – File manipulation . – Status information. – File modification. – Programming language support. – Program loading and execution. – Communications. – Application programs. Prepared by Imtithal Alnour Saeed 15 System Programs (Examples) • Status information – Some systems implement a registry - used to store and retrieve configuration information • File management - Create, delete, copy, rename, print, dump, list for manipulating files and directories. • status information that ask for information like date, time, amount of available memory, disk space, number of users etc. • Others provide detailed performance, logging, and debugging information like audit and log files. • The programs format and print the output to the terminal or other output devices. • Some systems programs implement a registry - used to store and retrieve configuration information. Prepared by Imtithal Alnour Saeed 16 System Programs (Examples) • File modification e.g. Text editors to create and modify files, special commands to search contents of files or perform transformations of the text. • Programming-language support - Compilers, assemblers, debuggers and interpreters. • Program loading and execution- Absolute loaders, relocatable loaders, linkage editors, and overlay-loaders, debugging systems for higher-level and machine language. • Communications - Provide the mechanism for creating virtual connections among processes, users, and computer systems. • Allow users to send messages to one another’s screens, browse web pages, send electronic-mail messages, log in remotely, transfer files from one machine to another. Prepared by Imtithal Alnour Saeed 17 Operating System Design and Implementation • Design and Implementation of OS not “solvable”, but some approaches have proven successful. • Reasons – Internal structure of different Operating Systems can vary. – Start by defining goals and specifications. – Affected by choice of hardware, type of system, users requirements. • 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 Prepared by Imtithal Alnour Saeed 18 Operating System Design and Implementation • It is important principle for Designers to separate between Policy and Mechanism. – Policies decide what will be done. – Mechanisms determine how to do something. • The separation of policy from mechanism is a very important principle, it allows maximum flexibility if policy decisions are to be changed later. • There are several designs for OS – – – – Simple Structure Layered Approach Microkernel System Structure Modules Prepared by Imtithal Alnour Saeed 19 Simple Structure • E.g. MS-DOS – written to provide the most functionality in the least space • MS-DOS Not divided into modules, structured but its interfaces and levels of functionality are not well separated. • Example: MS-DOS MS-DOS Layer Structure Prepared by Imtithal Alnour Saeed 20 Layered Approach • The operating system divided into layers, each built on top of lower layers. • The bottom layer (layer 0), is the hardware; the highest is the user interface. • With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers. • Example: UNIX systems Layered Operating System Prepared by Imtithal Alnour Saeed 21 UNIX • UNIX OS is layered structured consists of two separable parts: systems programs and the kernel. • Kernel consists of everything below the system-call interface and above the physical hardware. • Kernel provides the file system, CPU scheduling, memory management, and other operating-system functions; • A large number of functions for one level. Prepared by Imtithal Alnour Saeed 22 Microkernel System Structure • Moved as much from the kernel into “user” space. • Communication takes place between user modules using message passing. • Benefits of – Easier to extend the operating system (new modules added to user space). – Easier to port the operating system to new hardware design. – More reliable (less code is running in kernel mode). – More secure. • disadvs: – Performance overhead of user space to kernel space communication • Example: Tru64 UNIX Prepared by Imtithal Alnour Saeed 23 Mac OS X Structure Prepared by Imtithal Alnour Saeed 24 Modules • Most modern operating systems implement kernel modules. • kernel modules characterized by the use of object-oriented approach. • Each core component is separate. • Each modules can call the others over known interfaces. • Modules are loadable within the kernel as needed . • Overall, similar to layers but with more flexibility. • Example: Solaris, Linux, and Mac OS X. Prepared by Imtithal Alnour Saeed 25 Solaris Modular Approach Prepared by Imtithal Alnour Saeed 26 Virtual Machines • A virtual machine is a design approach takes the layered approach to its logical conclusion. • It treats hardware and the operating system kernel as they were all hardware. • A virtual machine provides an interface identical to the underlying bare hardware. • The operating system creates a virtual view of multiple processes, each executing on its own processor with its own memory. • The resources of the physical computer are shared to create the virtual machines. • CPU scheduling can create the appearance that users have their own processor. • Print spooling(responsible of allocating printer tasks) and a file system can provide virtual line printers and virtual device readers Prepared by Imtithal Alnour Saeed 27 Virtual Machines (Cont.) • Adv – The virtual-machine concept provides complete protection of system resources since each virtual machine is isolated from all other virtual machines. • this isolation permits no direct sharing of resources. – A virtual-machine system is a perfect vehicle for operating-systems research and development. • System development is done on the virtual machine, instead of on a physical machine and so does not disrupt normal system operation. • Disadv – The virtual machine concept is difficult to implement due to the effort required to provide an exact duplicate to the underlying machine Prepared by Imtithal Alnour Saeed 28 Virtual Machines vs Nonvirtual machine Non-virtual Machine Virtual Machine (a) Nonvirtual machine (b) virtual machine Prepared by Imtithal Alnour Saeed 29 Example:The Java Virtual Machine Prepared by Imtithal Alnour Saeed 30 End Prepared by Imtithal Alnour Saeed