L2operating systemsstructures

Page 1

Chapter 2: Operating-System Structures

perating System Concepts with Java – 7 th Edition

Prof. Hanafy M. Is


Chapter 2: Operating-System Structures      

Operating System Services User Operating System Interface System Calls Types of System Calls System Programs Operating System Structure

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail 2.2


Operating System Services 

One set of operating-system services provides functions that are helpful to the user:  User interface - Almost all operating systems have a user interface (UI)  Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch  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)  I/O operations - A running program may require I/O, which may involve a file or an I/O device.  File-system manipulation - The file system is of particular interest. Obviously, programs need to read and write files and directories, create and delete them, search them, list file Information, permission management.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail 2.3


Operating System Services (Cont.) 

One set of operating-system services provides functions that are helpful to the user (Cont):  Communications – Processes may exchange information, on the same computer or between computers over a network  Communications may be via shared memory or through message passing (packets moved by the OS)  Error detection – OS needs to be constantly aware of possible errors  May occur in the CPU and memory hardware, in I/O devices, 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

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail 2.4


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  Accounting - To keep track of which users use how much and what kinds of computer resources  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  Protection involves ensuring that all access to system resources is controlled  Security of the system from outsiders requires user authentication,

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail 2.5


User Operating System Interface - CLI There are two fundamental approaches for users to interface with the operating system:  Command-line interface (CLI) or command interpreter.  Graphical user interface (GUI)  CLI allows direct command entry:  Sometimes implemented in kernel,  sometimes implemented (as in UNIX and Windows XP) by systems program that is running when a job is initiated or when a user first logs on (on interactive systems)  Primarily fetches a command from user and executes it  Sometimes commands built-in (the command interrupt contains the code to execute the command)  An alternative, commands are implemented through system programs (as in UNIX); adding new features doesn’t require shell modification.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail 2.6


User Operating System Interface - GUI  

A GUI provides a mouse-based window-and-menu system as an interface. It provides a User-friendly desktop interface where the mouse is moved to position its pointer on images or icons on the screen.  Usually mouse, keyboard, and monitor  Icons represent files, programs, actions, etc  Various mouse buttons over objects in the interface cause various actions (provide information, options, execute function, open directory (known as a folder)  Invented at Xerox PARC in the early 1970s Many systems now include both CLI and GUI interfaces  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)

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail 2.7


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) (Note that the system-call names used throughout this text are generic)

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail 2.8


Example of System Calls ď °

System call sequence to copy the contents of one file to another file

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail 2.9


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)

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.10


API – System Call – OS Relationship

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.11


Standard C Library Example ď °

C program invoking printf() library call, which calls write() system call

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.12


System Call Parameter Passing 

Three general methods used to pass parameters to the OS  Simplest: pass the parameters in registers  Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register  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 Block and stack methods do not limit the number or length of parameters being passed

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.13


Parameter Passing via Table

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.14


Types of System Calls System calls can be grouped into five categories:  Process control  File management  Device management  Information maintenance  Communications

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.15


Process Control system calls 

End , abort  A running program needs to be able to halt its execution either normally (end) or abnormally (abort). Load, execute  A process or job executing one program may want to load and execute another program. Create process, terminate process  There is a system call for the purpose of create process or submit job. We may also need to terminate a created process if it is incorrect or no longer needed.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.16


Process Control system calls 

 

Get process attributes, set process attributes  We should be able to control the execution of the created processes.. This requires the ability to determine and set the attributes of a job or process. Wait for time  We may need to wait for the created processes to finish their execution. Either wait for a certain amount of time (Wait for time ) or wait for a specific event( wait event). The jobs or processors should signal when that event has occurred (signal event) Wait event, signal event Allocate and free memory

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.17


File management system calls    

Create file, delete file Open , close Read, write, reposition Get file attributes, set file attributes  File attributes include file name, file type, protection codes, accounting information, and so on.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.18


Device management system calls    

Request device, release device Read, write, reposition Get device attributes, set device attributes Logically attach or detach devices

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.19


Information maintenance system calls    

Get time or date, set time or date Get system data, set system data Get process, file, or device attributes Set process, file, or device attributes

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.20


Communication system calls    

Create, delete communication connection Send, receive messages Transfer status information Attach or detach remote devices

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.21


single-tasking system : MS-DOS execution 

There are many variations in process and job control. Next two examples:  single-tasking system (for example MS-DOS)  Multi-tasking system The MS-DOS operating system has a command interpreter that is invoked when the computer is started. To run a program:  It loads the program into memory, writing over most of itself to give the program as much memory as possible.  It sets the instruction pointer to the first instruction of the program  The program run, and either an error causes a trap, or the program executes a system call to terminate.  Then, the small portion of the command interpreter that was not overwritten resumes execution. It reloads the rest of the command interpreter from disk.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.22


MS-DOS execution

(a) At system startup (b) running a program

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.23


FreeBSD Running Multiple Programs 

FreeBSD (derived from Berkeley UNIX) is an example of a multitasking system.  When a user logs on to the system, the shell of the user’s choice is run.  This shell is similar to the MS-DOS shell in that it accepts commands and executing programs that the user requests.  However, the command interpreter may continue running while another program is executed.  To start a new process, the shell executes a fork() system call.  The selected program is loaded into memory via an exec() system call, and the program is executed.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.24


FreeBSD Running Multiple Programs

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.25


FreeBSD Running Multiple Programs 

 

The shell is then either waits for the process to finish or runs the process “in the background” ( in this case, the shell immediately requests another command) when a process is running in the background, the process cannot receive input directly from the keyboard, because the shell is using this resource. I/O is done through files or through a GUI. Meanwhile, the user is free to ask the shell to run other programs. When the process is done, it executes an exit() system call to terminate, returning a status code of 0 or a nonzero error code.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.26


System Programs 

System programs provide basic functionality to users so that users do not need to write their own programs to solve common problems. They Provide a convenient environment for program development and execution  Some of them are simply user interfaces to system calls; others are considerably more complex File management - Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.27


System Programs (cont’d) 

Status information  Some ask the system for info - date, time, amount of available memory, disk space, number of users  Others provide detailed performance, logging, and debugging information  Typically, these programs format and print the output to the terminal or other output devices

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.28


System Programs (cont’d) 

File modification  Text editors to create and modify files  Special commands to search contents of files. Programming-language support - Compilers, assemblers, debuggers and interpreters sometimes provided Program loading and execution- loaders, debugging systems for higher-level and machine language

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.29


System Programs (cont’d) 

Communications - Provide the mechanism for creating 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 In addition to systems programs, most operating systems are supplied with application programs (system utilities) that are useful in solving common problems or performing common operations.. Such programs include web browsers, compilers, database systems, and games

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.30


Operating system structure: Simple Structure 

Many commercial systems do not have well-defined structures. Such operating systems started as small, simple, and limited systems and then grew beyond their original scope. MS-DOS is an example of such a system:  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.  Application programs are able to access the basic I/O routines to write directly to the display and disk drives. Such freedom causes entire system crashes when user program fail.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.31


MS-DOS Layer Structure

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.32


Layered Approach  

 

A system can be made modular in many ways. One method is the layered approach. In which, 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. An operating system layer is an implementation of an object made up of data and the operations that can manipulate those data. A layer consists of data structures and a set of routines that can be invoked by higher level layers. A layer can invoke the operations on lower-level layers.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.33


Layered Operating System

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.34


Layered Approach 

 

The main advantage of the layered approach is  simplicity of construction and  debugging. With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers. If an error is found during debugging of a particular layer, the error must be on that layer, because the layers below it are already debugged. A layer does not need to know how the operations provided by lower layers are implemented. Each layer hides the existence of certain data structures, operations, and hardware from higher-level layers.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.35


Layered Approach 

The major difficulty with layered approach involves  defining appropriately the various layers.  for example, the device driver for baking store (disk space used by virtual-memory algorithm) must be at a lower level than the memory management routines, because memory management routines requires the ability to use the backing store.  Other requirements may not be obvious.  The backing store would be normally above the CPU scheduler, because the driver may need to wait for I/O and the CPU can be rescheduled during this time.  However, in large systems, the CPU scheduler may have more information about all active processes than can fit in memory.. Therefore information may need to be swapped in and out of memory, requiring the backing-store driver routine to be below the CPU scheduler.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.36


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

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.37


UNIX System Structure

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.38


Microkernel System Structure   

Moves as much from the kernel into “user” space Communication takes place between user modules using message passing Benefits:

adding a new service does not require modifying the kernel.

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. as

more operations are done in user mode than in kernel mode

Detriments:  Performance overhead of user space to kernel space communication

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.39


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

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.40


Solaris Modular Approach

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.41


Questions    

Q1: What is the purpose of system calls? Answer: System calls allow user-level processes to request services of the operating system. Q2: What are the five major activities of an operating system in regard to process management? Answer: a. The creation and deletion of both user and system processes b. The suspension and resumption of processes c. The provision of mechanisms for process synchronization d. The provision of mechanisms for process communication e. The provision of mechanisms for deadlock handling

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.42


Questions  

 

Q3: What are the three major activities of an operating system in regard to memory management? Answer: a. Keep track of which parts of memory are currently being used and by whom. b. Decide which processes are to be loaded into memory when memory space becomes available. c. Allocate and deallocate memory space as needed. Q4: What are the three major activities of an operating system in regard to secondary-storage management? Answer:  Free-space management.  Storage allocation.  Disk scheduling.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.43


Questions  

 

Q5: What is the purpose of the command interpreter? Why is it usually separate from the kernel? Answer: It reads commands from the user or from a file of commands and executes them, usually by turning them into one or more system calls. It is usually not part of the kernel since the command interpreter is subject to changes. Q6: What system calls have to be executed by a command interpreter or shell in order to start a new process? Answer: In Unix systems, a fork system call followed by an exec system call need to be performed to start a new process. The fork call clones the currently executing process, while the exec call overlays a new process based on a different executable over the calling process.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.44


Questions  

 

Q7: What is the purpose of system programs? Answer: System programs can be thought of as bundles of useful system calls. They provide basic functionality to users so that users do not need to write their own programs to solve common problems. Q8: What is the main advantage of the layered approach to system design? What are the disadvantages of using the layered approach? Answer: As in all cases of modular design, designing an operating system in a modular way has several advantages. The system is easier to debug and modify because changes affect only limited sections of the system rather than touching all sections of the operating system. Information is kept only where it is needed and is accessible only within a defined and restricted area, so any bugs affecting that data must be limited to a specific module or layer.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.45


Questions ď °

ď °

Q9: List five services provided by an operating system. Explain how each provides convenience to the users. Explain also in which cases it would be impossible for user-level programs to provide these services. Answer: a. Program execution. The operating system loads the contents (or sections) of a file into memory and begins its execution. A userlevel program could not be trusted to properly allocate CPU time. b. I/O operations. Disks, tapes, serial lines, and other devices must be communicated with at a very low level. The user need only specify the device and the operation to perform on it, while the system converts that request into device- or controllerspecific commands. User-level programs cannot be trusted to access only devices they should have access to and to access them only when they are otherwise unused.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.46


Questions c. File-system manipulation. There are many details in file creation, deletion, allocation, and naming that users should not have to perform. Blocks of disk space are used by files and must be tracked. Deleting a file requires removing the name file information and freeing the allocated blocks. Protections must also be checked to assure proper file access. User programs could neither ensure adherence to protection methods nor be trusted to allocate only free blocks and deallocate blocks on file deletion. d. Communications. Message passing between systems requires messages to be turned into packets of information, sent to the network controller, transmitted across a communications medium, and reassembled by the destination system. Packet ordering and data correction must take place. Again, user programs might not coordinate access to the network device, or they might receive packets destined for other processes.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.47


Questions ď °

e. Error detection. Error detection occurs at both the hardware and software levels. At the hardware level, all data transfers must be inspected to ensure that data have not been corrupted in transit. All data on media must be checked to be sure they have not changed since they were written to the media. At the software level, media must be checked for data consistency; for instance, whether the number of allocated and unallocated blocks of storage match the total number on the device. There, errors are frequently processindependent (for instance, the corruption of data on a disk), so there must be a global program (the operating system) that handles all types of errors. Also, by having errors processed by the operating system, processes need not contain code to catch and correct all the errors possible on a system.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.48


Questions  

 

Q10: What are the main advantages of the microkernel approach to system design? Answer: Benefits typically include the following (a) adding a new service does not require modifying the kernel, (b) it is more secure as more operations are done in user mode than in kernel mode, and (c) a simpler kernel design and functionality typically results in a more reliable operating system. Q11: Why do some systems store the operating system in firmware, and others on disk? Answer: For certain devices, such as handheld PDAs and cellular telephones, a disk with a file system may be not be available for the device. In this situation, the operating system must be stored in firmware.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.49


Questions ď °

ď °

Q12: How could a system be designed to allow a choice of operating systems to boot from? What would the bootstrap program need to do? Answer: Consider a system that would like to run both Windows XP and three different distributions of Linux (e.g., RedHat, Debian, and Mandrake). Each operating system will be stored on disk. During system boot-up, a special program (which we will call the boot manager) will determine which operating system to boot into. This means that rather initially booting to an operating system, the boot manager will first run during system startup. It is this boot manager that is responsible for determining which system to boot into. Typically boot managers must be stored at certain locations of the hard disk to be recognized during system startup. Boot managers often provide the user with a selection of systems to boot into; boot managers are also typically designed to boot into a default operating system if no choice is selected by the user.

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.50


Assignment 2 

   

Q1. The services and functions provided by an operating system can be divided into two main categories. Briefly describe the two categories and discuss how they differ. Q2. List five services provided by an operating system that are designed to make it more convenient for users to use the computer system. In what cases it would be impossible for user-level programs to provide these services? Explain. Q3. Describe three general methods for passing parameters to the operating system. Q4. What are the five major activities of an operating system in regard to file management? Q5. What are the advantages and disadvantages of using the same system call interface for manipulating both files and devices? Q6. What is the purpose of the command interpreter? Why is it usually separate from the kernel? Would it be possible for the user to develop a new command interpreter using the system-call interface provided by the operating system?

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.51


Assignment 2  

Q7. What are the two models of inter process communication? What are the strengths and weaknesses of the two approaches? Q8. It is sometimes difficult to achieve a layered approach if two components of the operating system are dependent on each other. Identify a scenario in which it is unclear how to layer two system components that require tight coupling of their functionalities. Q9. What is the main advantage of the microkernel approach to system design? How do user programs and system services interact in a microkernel architecture? What are the disadvantages of using the microkernel approach? Q10. In what ways is the modular kernel approach similar to the layered approach? In what ways does it differ from the layered approach?

ef: Operating System Concepts with Java – 7 th Edition,

Prof. Dr. Hanafy M. Ismail2.52


End of Chapter 2

perating System Concepts with Java – 7 th Edition

Prof. Hanafy M. Is


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.