Module 1: Introduction to OS Dr Narayana Swamy Ramaiah , Professor and HoD
Module 1 : Introduction Basics of Operating Systems: Definition, System Calls ā Types. Operating System Structure: Layered Structure, Microkernel, Modules, Hybrid Systems ā Mac OS X, iOS , Android.
What Does the Term Operating System Mean? An operating system is āfill in the blanksā What about: Car Airplane Printer Washing Machine Toaster Compiler Etc.
What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware Operating system goals: Execute user programs and make solving user problems easier Make the computer system convenient to use Use the computer hardware in an efficient manner
Computer System Structure Computer system can be divided into four components: Hardware ā provides basic computing resources CPU, memory, I/O devices Application programs ā define the ways in which the system resources are used to solve the computing problems of the users Word processors, compilers, web browsers, database systems, video games Operating system Controls and coordinates use of hardware among various applications and users Users People, machines, other computers
Abstract View of Components of Computer
What Operating Systems Do Depends on the point of view ā user view Stand alone system-Users want convenience, ease of use and good performance Don ā t care about resource utilization But shared computer such as mainframe or minicomputer must keep all users happy Operating system is a resource allocator and control program making efficient use of HW and managing execution of user programs Users of dedicate systems such as workstations have dedicated resources but frequently use shared resources from servers Mobile devices like smartphones and tables are resource poor, optimized for usability and battery life Mobile user interfaces such as touch screens, voice recognition Some computers have little or no user interface, such as embedded computers in devices and automobiles Run primarily without user intervention
System view Operating system can be viewed as a resource allocator. Resources can be CPU time, memory space, storage space, I/O devices, and so on. how to allocate resources to specific programs and users so that it can operate the computer system efficiently and fairly. An operating system is a control program A control program manages the execution of user programs to prevent errors and improper use of the computer. It is especially concerned with the operation and control of I/O devices .
Defining Operating Systems Computers are Present in toasters, cars, ships, spacecraft, game machines, cable TV tuners and industrial control systems Computing started as an experiment to determine what could be done and quickly moved to fixed-purpose systems for military uses, such as code breaking and trajectory plotting, and governmental uses, such as census calculation . OS was Born when fixed use computers for military became more general purpose and needed resource management and program control In the 1960s, Mooreās Law predicted that the number of transistors on an integrated circuit would double every 18 months , and that prediction has held true. Computers gained in functionality and shrank in size, leading to a vast number of uses and a vast number and variety of operating systems
Operating Sy st em Definition No universally accepted definition The common functions of controlling and allocating resources are then brought together into one piece of software : the operating system . ā Everything a vendor ships when you order an operating system ā is a good approximation But varies wildly ā The one program running at all times on the computer ā is the kernel, part of the operating system Along with kernal two other programs that are runnning A system program (ships with the operating system, but not part of the kernel) , or An application program , all programs not associated with the operating system Microsoft was found guilty of using its operating-system monopoly to limit competition.
Operating Sy st em Definition Todayās OSes for general purpose and mobile computing also include middleware ā a set of software frameworks that provide additional services to application developers such as databases, multimedia, graphics. For example, each of the two most prominent mobile operating systemsāAppleās iOS and Googleās Androidāfeatures
Operating-System Operations Bootstrap program ā simple code to initialize the system, load the kernel Kernel loads Starts system daemons (services provided outside of the kernel) Kernel interrupt driven (hardware and software) Hardware interrupt by one of the devices Software interrupt ( exception or trap ): Software error (e.g., division by zero) Request for operating system service ā system call Other process problems include infinite loop, processes modifying each other or the operating system
Multiprogramming (Batch system) Single user cannot always keep CPU and I/O devices busy Multiprogramming organizes jobs (code and data) so CPU always has one to execute A subset of total jobs in system is kept in memory One job selected and run via job scheduling When job has to wait (for I/O for example), OS switches to another job
Multitasking (Timesharing) A logical extension of Batch systemsā the CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing Response time should be < 1 second Each user has at least one program executing in memory ļ process If several jobs ready to run at the same time ļ CPU scheduling If processes don ā t fit in memory, swapping moves them in and out to run Virtual memory allows execution of processes not completely in memory
Memory Layout for Multiprogrammed System
Dual-mode Operation Dual-mode operation allows OS to protect itself and other system components User mode and kernel mode Mode bit provided by hardware Provides ability to distinguish when system is running user code or kernel code. When a user is running ļ mode bit is āuserā When kernel code is executing ļ mode bit is ākernelā How do we guarantee that user does not explicitly set the mode bit to ākernelā? System call changes mode to kernel, return from call resets it to user Some instructions designated as privileged , only executable in kernel mode
Transition from User to Kernel Mode
Timer Timer to prevent infinite loop (or process hogging resources) Timer is set to interrupt the computer after some time period Keep a counter that is decremented by the physical clock Operating system set the counter (privileged instruction) When counter zero generate an interrupt Set up before scheduling process to regain control or terminate program that exceeds allotted time
Operating System Services Operating systems provide an environment for execution of programs and services to programs and users 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 ) , touch-screen , 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. Programs need to read and write files and directories, create and delete them, search them, list file Information, permission management.
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
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 Many types of resources - CPU cycles, main memory, file storage, I/O devices. Logging - 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 multiuser 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, extends to defending external I/O devices from invalid access attempts
A View of Operating System Services
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 Programming 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
Example of System Calls System call sequence to copy the contents of one file to another file cp in.txt out.txt
Types of System Calls Process control create process, terminate process end, abort load, execute get process attributes, set process attributes wait for time wait event, signal event allocate and free memory Dump memory if error Debugger for determining bugs , single step execution Locks for managing access to shared data between processes
File management create file, delete file open, close file read, write, reposition get and set file attributes Device management request device, release device read, write, reposition get device attributes, set device attributes logically attach or detach devices Types of System Calls (Cont.)
Types of System Calls (Cont.) Information maintenance get time or date, set time or date get system data, set system data get and set process, file, or device attributes Communications create, delete communication connection send, receive messages if message passing model to host name or process name From client to server Shared-memory model create and gain access to memory regions transfer status information attach and detach remote devices
Types of System Calls (Cont.) Protection Control access to resources Get and set permissions Allow and deny user access
Examples of Windows and Unix System Calls
Layered Approach Monolithic approach is often tightly coupled. Layered approach is loosely coupled 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. With modularity , layers are selected such that each uses functions (operations) and services of only lower-level layers Simplifies debugging and system verification
Microkernels Moves as much from the kernel into user space Mach is an example of microkernel Mac OS X kernel ( Darwin ) partly based on Mach Communication takes place between user modules using message passing 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
Microkernel System Structure
Modules Many modern operating systems implement loadable kernel mo dules ( LKMs ) 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 Linux, Solaris, etc.
Hybrid Systems Most modern operating systems are not one pure model Hybrid combines multiple approaches to address performance, security, usability needs Linux , monolithic ( OS in single address space for improved performance), plus modular for dynamic loading of functionality Windows mostly monolithic, plus microkernel for different subsystem personalities
macOS and iOS Appleās macOS operating system is designed to run primarily on desktop and laptop computer systems, whereas iOS is a mobile operating system designed for the iPhone smartphone and iPad tablet computer. general architecture of these two systems and various layers User experience layer. This layer defines the software interface that allows users to interact with the computing devices. mac OS uses the Aqua user interface, which is designed for a mouse or trackpad , whereas i OS uses the Springboard user interface, which is designed for touch devices. Application frameworks layer. This layer includes the Cocoa and Cocoa Touch frameworks, which provide an API for the Objective-C and Swift programming languages.
macOS and iOS Core frameworks. This layer defines frameworks that support graphics and media including, Quicktime and OpenGL. Kernel environment. This environment, also known as Darwin, includes the Mach microkernel and the BSD UNIX kernel.
Some significant distinctions between macOS and iOS include the following: Because macOS is intended for desktop and laptop computer systems, it is compiled to run on Intel architectures . iOS is designed for mobile devices and thus is compiled for ARM-based architectures. Similarly, the iOS kernel has been modified somewhat to address specific features and needs of mobile systems, such as power management and aggressive memory management. Additionally, iOS has more stringent security settings than macOS . The iOS operating system is generally much more restricted to developers than macOS and may even be closed to developers. For example, iOS restricts access to POSIX and BSD APIs on iOS , whereas they are openly available to developers on macOS .
Darwin Darwin uses hybrid structure , Darwin is a layered system that consists primarily of the Mach microkernel and the BSD UNIX kernel. Darwin provides two system-call interfaces: Mach system calls (known as traps) and BSD system calls (which provide POSIX functionality).
Darwin Much of the functionality provided by Mach is available through kernel abstractions, which include tasks (a Mach process), threads, memory objects, and ports (used for IPC). the kernel environment provides an I/O kit for development of device drivers and dynamically loadable modules (which macOS refers to as kernel extensions, or kexts ). Message passing within Mach still does occur, but no copying is necessary, as the services have access to the same address space
Android Developed by Open Handset Alliance (mostly Google) Open Source Similar stack to iOS , provides frameworks supporting graphics, audio, and hardware features. Provides a platform to develop mobile applications that can run on android enabled devices . Google has designed a separate Android API for Java development . Java applications are compiled into a form that can execute on the Android Runtime ART (AOT compilation), a virtual machine designed for Android and optimized for mobile devices with limited memory and CPU processing capabilities. Programs written in Java Native Interface (JNI) are generally not portable The set of native libraries available for Android applications includes frameworks for developing web browsers ( webkit ), database support ( SQLite ), and network support, such as secure sockets (SSLs).
Android Architecture
Google has chosen to abstract the physical hardware through the hardware abstraction layer, or HAL. Google instead developed the Bionic standard C library for Android, for the slower CPUs that characterize mobile devices Made changes in memory management and allocation and has added a new form of IPC known as Binder