Chapter 2 Struktur OperatingSystem Bab 2 Struktur OperatingSystem
Chapter 2: Struktur Operating-System
Bab 2: Struktur Operating-System n Operating System Services n User Operating System Interface n System Calls n Types of System Calls n System Programs n Operating System Design and Implementation n Operating System Structure n Virtual Machines n Operating System Generation n System Boot Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 2 Silberschatz, Galvin and Gagne © 2005
Tujuan n To describe the services an operating system provides to users, processes, and other systems n To discuss the various ways of structuring an operating system n To explain how operating systems are installed and customized and how they boot Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 3 Silberschatz, Galvin and Gagne © 2005
OS Structure 4 Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 4 Silberschatz, Galvin and Gagne © 2005
Struktur OS n An operating system is composed of a kernel, possibly some service, and posssibly some user-level libraries. n The kernel provides operating system services through a set of procedures, which may be invoked by user processes through system calls. Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 5 Silberschatz, Galvin and Gagne © 2005
User Interface n CLI: Command Line n GUI: User-friendly Interface (CLI) or command interpreter (shell) l desktop interface l in kernel or as a system program, l Many flavors l fetches a command from user and executes it Icons represent files, programs, actions, etc. n Many operating systems now include both CLI and GUI interfaces l 4 Command may be built-in, 4 Command may be another program Linux: command shells available (CLI); KDE as GUI 6 Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 6 Silberschatz, Galvin and Gagne © 2005
Bourne Shell Command Interpreter 7 Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 7 Silberschatz, Galvin and Gagne © 2005
The Mac. OS X GUI 8 Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 8 Silberschatz, Galvin and Gagne © 2005
Kernel n Kernel adalah program yang bertugas mengatur input/output request dari aplikasi/user menuju resource dari komputer, yaitu : CPU, memory, I/O, atau devais lainnya dari komputer Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 9 Silberschatz, Galvin and Gagne © 2005
System Calls n System call adalah bagaimana cara program mengakses layanan dari kernel sistem operasi. n Ditulis dalam bahasa aras tinggi (C or C++) n Biasanya programmer lebih memilih menggunakan Application Program Interface (API) daripada melakukan system call secara langsung. n Tiap OS memiliki system call yang berbeda n 3 APIs paling populer adalah : Win 32 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) Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 10 Silberschatz, Galvin and Gagne © 2005
The relationship between applications, the C library, and the kernel with a call to printf(). /* Hello World program */ #include<stdio. h> main() { printf("Hello World"); } Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 11 Silberschatz, Galvin and Gagne © 2005
Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 12 Silberschatz, Galvin and Gagne © 2005
Example of Different APIs Issuing the Same System Call n In Linux, the malloc( ) , calloc( ) , and free( ) APIs are implemented in the libc library. n The code in this library keeps track of the allocation and deallocation requests and uses the brk( ) system call to enlarge or shrink the process heap. l P. S. : See the section "Managing the Heap" in Chapter 9. 13 Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 13 Silberschatz, Galvin and Gagne © 2005
Example of Standard API n Consider the Read. File() function in the Win 32 API – a function for reading from a file n The parameters passed to Read. File() are l HANDLE file – the file to be read l LPVOID buffer – a buffer where the data will be read into and written from l DWORD bytes. To. Read – the number of bytes to be read into the buffer (buffer size) l LPDWORD bytes. Read – the number of bytes read during the last read l LPOVERLAPPED ovl – indicates if overlapped (non-blocking) I/O is to be used Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 14 Silberschatz, Galvin and Gagne © 2005
Example of System Calls n System call sequence to copy the contents of one file to another file Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 15 Silberschatz, Galvin and Gagne © 2005
API – System Call – OS Relationship Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 16 Silberschatz, Galvin and Gagne © 2005
API – System Call Implementation n The interface to the services provided by the OS has two parts: 1. 2. Higher language interface – a part of a system library • Executes in user mode • Implemented to accept a standard procedure call • Traps to the Part 2 Kernel part • Executes in system mode • Implements the required system service • May cause blocking the caller (forcing it to wait) • After completion returns back to Part 1 (may report the success or failure of the call) Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 17 Silberschatz, Galvin and Gagne © 2005
How the System Call Interface is Implemented • The application program makes a System Call: − A system library routine is called first − It transforms the call to the system standard (native API) and traps to the kernel − Control is taken by the kernel running in the system mode − According to the service “code”, the Call dispatcher invokes the responsible part of the Kernel − Depending on the nature of the required service, the kernel may block the calling process − After the call is finished, the calling process execution resumes obtaining the result (success/failure) as if an ordinary function was called 11 steps to execute the service fread (fd, buffer, nbytes) Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 18 Silberschatz, Galvin and Gagne © 2005
Example of System Calls n System call sequence to copy the contents of one file to another file Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 19 Silberschatz, Galvin and Gagne © 2005
File copy with system call #include <stdio. h> #include <stdlib. h> #include <fcntl. h> #include <errno. h> #include <sys/types. h> #include <unistd. h> #define BUF_SIZE 8192 int main(int argc, char* argv[]) { int input_fd, output_fd; /* Input and output file descriptors */ ssize_t ret_in, ret_out; /* Number of bytes returned by read() and write() */ char buffer[BUF_SIZE]; /* Character buffer */ Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 20 Silberschatz, Galvin and Gagne © 2005
/* Are src and dest file name arguments missing */ if(argc != 3) { printf ("Usage: cp file 1 file 2"); return 1; } /* Create input file descriptor*/ input_fd = open (argv [1], O_RDONLY); if (input_fd == -1) { perror ("open"); return 2; } /* Create output file descriptor */ output_fd = open(argv[2], O_WRONLY | O_CREAT, 0644); if (output_fd == -1) { perror("open"); return 3; } Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 21 Silberschatz, Galvin and Gagne © 2005
/* Copy process */ while((ret_in = read (input_fd, &buffer, BUF_SIZE)) > 0) { ret_out = write (output_fd, &buffer, (ssize_t) ret_in); if(ret_out != ret_in) { /* Write error */ perror("write"); return 4; } } /* Close file descriptors */ close (input_fd); close (output_fd); return (EXIT_SUCCESS); } Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 22 Silberschatz, Galvin and Gagne © 2005
Running … n gcc -Wall -o sp_linux_copy. c n. /sp_linux_copy <source_file. txt> <destination_file. txt> Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 23 Silberschatz, Galvin and Gagne © 2005
Types of System Calls n Process control n File management n Device management n Information maintenance n Communications Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 24 Silberschatz, Galvin and Gagne © 2005
System Call Example Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 25 Silberschatz, Galvin and Gagne © 2005
Solaris 10 dtrace Following System Call Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 26 Silberschatz, Galvin and Gagne © 2005
MS-DOS execution (a) At system startup (b) running a program Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 27 Silberschatz, Galvin and Gagne © 2005
Free. BSD Running Multiple Programs Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 28 Silberschatz, Galvin and Gagne © 2005
Operating System Services l User interface - Almost all operating systems have a user interface (UI) 4 Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch l Program execution - The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error) l I/O operations - A running program may require I/O, which may involve a file or an I/O device. (More on next slide) Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 29 Silberschatz, Galvin and Gagne © 2005
n File-system manipulation n Obviously, programs need to read and write files and directories, create and delete them, search them, list file Information, permission management. n Communications l Processes may exchange information, on the same computer or between computers over a network l Communications may be via shared mempassing (packets moved by the OS)ory or through message Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 30 Silberschatz, Galvin and Gagne © 2005
Operating System Services (Cont. ) l Error detection 4 OS needs to be constantly aware of possible errors 4 May occur in the CPU and memory hardware, in I/O devices, in user program 4 For each type of error, OS should take the appropriate action to ensure correct and consistent computing 4 Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 31 Silberschatz, Galvin and Gagne © 2005
l Resource allocation – 4 When multiple users or multiple jobs are running concurrently, resources must be allocated to each of them 4 Many types of resources - Some (such as CPU cycles, main memory, and file storage) may have special allocation code, others (such as I/O devices) may have general request and release code. Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 32 Silberschatz, Galvin and Gagne © 2005
n Accounting - To keep track of which users use how much and what kinds of computer resources n Protection and security - The owners of information stored in a multi-user or networked computer system may want to control use of that information, concurrent processes should not interfere with each other l Protection involves ensuring that all access to system resources is controlled l Security of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attempts Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 33 Silberschatz, Galvin and Gagne © 2005
Windows 7 Service Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 34 Silberschatz, Galvin and Gagne © 2005
Linux Service n In Linux, service is the same as daemon Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 35 Silberschatz, Galvin and Gagne © 2005
The assembly vs. high-level language issue n Advantages of high-level languages: easy to use and maintain, and more available programming tools n Disadvantages of high-level languages: slower and more space n Many systems were written in both with a small percentage (e. g. , 10%) of assembly language for the most speed demanding low level portion. Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 36 Silberschatz, Galvin and Gagne © 2005
Operating System Design and Implementation n Design and Implementation of OS not “solvable”, but some approaches have proven successful n Internal structure of different Operating Systems can vary widely n Start by defining goals and specifications n Affected by choice of hardware, type of system n User goals and System goals l User goals – operating system should be convenient to use, easy to learn, reliable, safe, and fast l System goals – operating system should be easy to design, implement, and maintain, as well as flexible, reliable, error-free, and efficient Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 37 Silberschatz, Galvin and Gagne © 2005
Operating System Design and Implementation (Cont. ) n Important principle to separate Policy: What will be done? Mechanism: How to do it? n Contoh : timer l policy : berapa lama timer diset untuk tiap user ; l mekanisme : bagaimana membuat timer untuk melakukan proteksi CPU n Mechanisms determine how to do something, policies decide what will be done l The separation of policy from mechanism is a very important principle, it allows maximum flexibility if policy decisions are to be changed later Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 38 Silberschatz, Galvin and Gagne © 2005
OS Structure The OS (a simplified view) Command Interpreter Information Services Error Handling File System Accounting System Protection System Process Management Memory Management Secondary Storage Management I/O System Hardware Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 39 14 Silberschatz, Galvin and Gagne © 2005
OS Structure n An OS consists of all of these components, plus lots of others, plus system service routines, plus system programs (privileged and non-privileged), plus. . n The big issue: 4 how do we organize all of this? 4 what are the entities and where do they exist? 4 how does these entities cooperate? n Basically, how do we build a complex system that’s: 4 performant 4 reliable 4 extensible Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 40 Silberschatz, Galvin and Gagne © 2005
OS Structure n Simple Approach n Monolithic Approach n Layered Approach n Micro Kernel Approach n Modules Approach Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 41 Silberschatz, Galvin and Gagne © 2005
Simple Approach n MS-DOS – written to provide the most functionality in the least space l Not divided into modules l Although MS-DOS has some structure, its interfaces and levels of functionality are not well separated Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 42 Silberschatz, Galvin and Gagne © 2005
MS-DOS Structure Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 43 Silberschatz, Galvin and Gagne © 2005
Monolithic Approach n Functionality of the OS is invoked with simple function calls within the kernel, which is one large program. n Device drivers are loaded into the running kernel and become part of the kernel. n Contoh : linux dan windows 9 x Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 44 Silberschatz, Galvin and Gagne © 2005
Monolithic Structure Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 45 Silberschatz, Galvin and Gagne © 2005
Monolithic : UNIX n UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring. The UNIX OS consists of two separable parts l Systems programs l The kernel 4 Consists of everything below the system-call interface and above the physical hardware 4 Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 46 Silberschatz, Galvin and Gagne © 2005
UNIX System Structure Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 47 Silberschatz, Galvin and Gagne © 2005
Layered Approach n The operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface. n With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers n The main advantage is simplicity of construction and debugging. n The main difficulty is defining the various layers. n The main disadvantage is that the OS tends to be less efficient than other implementations n Contoh : The Microsoft Windows NT Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 48 Silberschatz, Galvin and Gagne © 2005
Layered Operating System 0 : processor and switching between process 1 : memory management 2. Komunikasi antar proses 3. Manajemen I/O devices dan information stream buffering 4. User program 5. System operator process Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 49 Silberschatz, Galvin and Gagne © 2005
n The NT Architecture has 5 layers. l Application - Runs in user mode. l Subsystems - Runs in user mode. l Executive Services - Runs in kernel mode. l Kernel - Runs in kernel mode. l HAL - Runs in kernel mode. Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 50 Silberschatz, Galvin and Gagne © 2005
Win NT Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 51 Silberschatz, Galvin and Gagne © 2005
Microkernel Approach n Moves as much from the kernel into “user” space n Communication takes place between user modules using message passing n Benefits: l Easier to extend a microkernel l Easier to port the operating system to new architectures l More reliable (less code is running in kernel mode) l More secure n Detriments: l Performance overhead of user space to kernel space communication n Contoh : l Minix, dikembangkan oleh Andrew Tanenbaum l Mach, which was developed at Carnegie Mellon University in the mid 1980’s. Mach was used as the low-level part of Apple OS X (also known as Darwin). Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 52 Silberschatz, Galvin and Gagne © 2005
Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 53 Silberschatz, Galvin and Gagne © 2005
Mach kernel in OS X Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 54 Silberschatz, Galvin and Gagne © 2005
Modules n Most modern operating systems implement kernel modules l Uses object-oriented approach l Each core component is separate l Each talks to the others over known interfaces l Each is loadable as needed within the kernel n Overall, similar to layers but with more flexible Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 55 Silberschatz, Galvin and Gagne © 2005
Solaris Modular Approach Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 56 Silberschatz, Galvin and Gagne © 2005
Virtual Machines n 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 n A virtual machine provides an interface identical to the underlying bare hardware n The operating system creates the illusion of multiple processes, each executing on its own processor with its own (virtual) memory Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 57 Silberschatz, Galvin and Gagne © 2005
Virtual Machines (Cont. ) n The resources of the physical computer are shared to create the virtual machines l CPU scheduling can create the appearance that users have their own processor l Spooling and a file system can provide virtual card readers and virtual line printers l A normal user time-sharing terminal serves as the virtual machine operator’s console Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 58 Silberschatz, Galvin and Gagne © 2005
Virtual Machines (Cont. ) Non-virtual Machine Virtual Machine (a) Nonvirtual machine (b) virtual machine Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 59 Silberschatz, Galvin and Gagne © 2005
Virtual Machines (Cont. ) n The virtual-machine concept provides complete protection of system resources since each virtual machine is isolated from all other virtual machines. This isolation, however, permits no direct sharing of resources. n 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. n The virtual machine concept is difficult to implement due to the effort required to provide an exact duplicate to the underlying machine Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 60 Silberschatz, Galvin and Gagne © 2005
VMware Architecture Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 61 Silberschatz, Galvin and Gagne © 2005
The Java Virtual Machine Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 62 Silberschatz, Galvin and Gagne © 2005
Operating System Generation n Operating systems are designed to run on any of a class of machines; the system must be configured for each specific computer site n SYSGEN program obtains information concerning the specific configuration of the hardware system n Booting – starting a computer by loading the kernel n Bootstrap program – code stored in ROM that is able to locate the kernel, load it into memory, and start its execution Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 63 Silberschatz, Galvin and Gagne © 2005
System Boot n Operating system must be made available to hardware so hardware can start it l Small piece of code – bootstrap loader, locates the kernel, loads it into memory, and starts it l Sometimes two-step process where boot block at fixed location loads bootstrap loader l When power initialized on system, execution starts at a fixed memory location 4 Firmware used to hold initial boot code Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 64 Silberschatz, Galvin and Gagne © 2005
Sumber n http: //www 2. cs. uic. edu/~jbell/Course. Notes/Operating. Systems/2_St ructures. html Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 65 Silberschatz, Galvin and Gagne © 2005
Latihan 1. Jelaskan perbedaan arsitektur von Neuman dan Hardvard 2. Jelaskan perbedaan RISC dan CISC 3. Sebutkan arsitektur prosesor yang ada 4. Jelaskan kelemahan dan kelebihan microkernel vs monolithic kernel ( baca debat antara linux torvald dan tanenbaum) Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 66 Silberschatz, Galvin and Gagne © 2005
Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 67 Silberschatz, Galvin and Gagne © 2005
End of Chapter 2
System Call Implementation n Typically, a number associated with each system call l System-call interface maintains a table indexed according to these numbers n The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values n The caller need know nothing about how the system call is implemented l Just needs to obey API and understand what OS will do as a result call l Most details of OS interface hidden from programmer by API 4 Managed by run-time support library (set of functions built into libraries included with compiler) Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 69 Silberschatz, Galvin and Gagne © 2005
System Call Parameter Passing n Often, more information is required than simply identity of desired system call l Exact type and amount of information vary according to OS and call n Three general methods used to pass parameters to the OS l Simplest: pass the parameters in registers 4 In some cases, may be more parameters than registers l Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register 4 This approach taken by Linux and Solaris Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system l Block and stack methods do not limit the number or length of parameters being passed l Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 70 Silberschatz, Galvin and Gagne © 2005
Parameter Passing via Table Operating System Concepts – 7 th Edition, Jan 14, 2005 2. 71 Silberschatz, Galvin and Gagne © 2005
- Slides: 71