0% found this document useful (0 votes)
4 views

Operating-System Structures

; kıjhuygthyujolpğşi

Uploaded by

Soha Aa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Operating-System Structures

; kıjhuygthyujolpğşi

Uploaded by

Soha Aa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Dr.

Mesut ÜNLÜ
Dr. Mesut ÜNLÜ

Operating-System Structures

Asist.Prof. Mesut ÜNLÜ

1
Dr. Mesut ÜNLÜ
Operating-System Structures Dr. Mesut ÜNLÜ

▪ Operating System Services

▪ User Operating System Interface

▪ System Calls

▪ System Programs

▪ Operating System Design and Implementation

▪ Operating System Structure

▪ Operating System Debugging

▪ Operating System Generation

▪ System Boot
Dr. Mesut ÜNLÜ
Operating System Services Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ
Operating System Services Dr. Mesut ÜNLÜ

▪ Operating systems provide services to programs and users. One set of operating-system
services provides functions that are helpful to the user:

o User interface - Almost all operating systems have a user interface (UI).

• Varies between Command-Line (CLI), Graphics User Interface (GUI), touch-screen


interface

o 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)

o I/O operations - A running program may require I/O, which may involve a file or an
I/O device. For specific devices, special functions may be desired (such as reading from a
network interface or writing to a file system).
Dr. Mesut ÜNLÜ
Operating System Services Dr. Mesut ÜNLÜ

▪ 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, and
permission management.

▪ Communications – Processes may exchange information, on the same computer or between


computers over a network
o 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


o Errors may occur in the CPU and memory hardware, in I/O devices, in user program

o For each type of error, OS should take the appropriate action to ensure correct and consistent computing

o Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the
system
Dr. Mesut ÜNLÜ
Operating System Services Dr. Mesut ÜNLÜ

▪ Resource allocation - When multiple users or multiple jobs running concurrently, resources
must be allocated to each of them
o Many types of resources - CPU cycles, main memory, file storage, I/O devices.

▪ 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 multiuser or networked


computer system may want to control use of that information, concurrent processes should
not interfere with each other
o Protection involves ensuring that all access to system resources is controlled

o Security of the system from outsiders requires user authentication, and extends to defending external I/O
devices from invalid access attempts
Dr. Mesut ÜNLÜ
User and Operating-System Interfaces Dr. Mesut ÜNLÜ

▪ Command Interpreters

▪ CLI or command interpreter allows direct command entry

o Sometimes implemented in the kernel, sometimes by systems program

o On systems with multiple command interpreters to choose from, the interpreters


are known as shells. The Linux command line is provided by a program called the
shell. on UNIX and Linux systems, a user may choose among several different shells:

• CShell, Bourne-Again Shell, Korn Shell, and others.

o Most shells provide similar functionality, and a user’s choice of which shell to use is
generally based on personal preference.
Dr. Mesut ÜNLÜ
User and Operating-System Interfaces Dr. Mesut ÜNLÜ

The bash shell command interpreter in macOS


Dr. Mesut ÜNLÜ
User and Operating-System Interfaces Dr. Mesut ÜNLÜ

▪ Shell Scripting Sample

o Let's write a script prompting user to enter two numbers and to find the greatest
and sum of the given numbers.

o Let's use an online editor to write this script.

• https://www.onlinegdb.com/online_bash_shell
Dr. Mesut ÜNLÜ
User and Operating-System Interfaces Dr. Mesut ÜNLÜ

▪ Shell Scripting Sample (Windows)

o Open the command prompt by an admin privileges

• Show open programs

• Show the tree of the Current Directory or Specified Drive

• Show the version of the OS

• Start website-address

• List all items in a directory

• Prompt a message "Welcome to OS Course«

• Use "prompt $P$G" to turnback to command prompt


Dr. Mesut ÜNLÜ
User and Operating-System Interfaces Dr. Mesut ÜNLÜ

▪ Graphical User Interface

o A second strategy for interfacing with the operating system is through a user-friendly
graphical user interface, or GUI. Most personal computers offer a GUI.

o The GUI was invented by Douglas Engelbart and his research group at the
Stanford Research Institute.

• 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)
Dr. Mesut ÜNLÜ
User and Operating-System Interfaces Dr. Mesut ÜNLÜ

▪ Graphical User Interface

o Touch-Screen Interface

• Touch screen devices require new interfaces


➢ Mouse not possible or not desired

➢ Actions and selection based on gestures

➢ Virtual keyboard for text entry

• Voice commands.

The iPhone touch screen


Dr. Mesut ÜNLÜ
User and Operating-System Interfaces Dr. Mesut ÜNLÜ

▪ Graphical User Interface

o The Mac OS X GUI

The macOS GUI


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ System calls provide an interface to the services made available by an operating system.

▪ These calls are generally available as functions written in C and C++, although
certain low-level tasks (for example, tasks where hardware must be accessed directly)
may have to be written using assembly-language instructions.

▪ Explicitly triggered by a program instruction.

▪ A call from a C program might look like this:

count = read(fd, buffer, nbytes);

▪ The system call (and the library procedure) returns the number of bytes actually read in
count. This value is normally the same as nbytes, but may be smaller, if, for example,
end-of-file is encountered while reading.
Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ More Details

▪ A system call is a way for a program (in user mode) to request services from the operating system
(in kernel mode). It allows programs to interact with system resources like files, devices, or
memory.

▪ A system call is explicitly triggered by the running program when it needs a service from the OS.
The program uses a special instruction (often called a trap or syscall) to switch from user mode to
kernel mode, allowing access to protected system functions.

▪ Examples:
o Opening a file (open() system call in UNIX-like systems).

o Allocating memory.

o Creating or managing processes (fork() in UNIX).


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Key Differences Among Interrupts and System Calls

▪ Interrupts are system-wide, asynchronous events that can come from both hardware and software and need
immediate attention, while system calls are specific requests made by programs to the operating system to
perform certain services.
Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

count = read(fd, buffer, nbytes);


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ System Call Example

▪ The UNIX cp command:

cp in.txt out.txt

▪ This command copies the


input file in.txt to the output
file out.txt.
Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Application Programming Interface (API)

▪ Frequently, systems execute thousands of system calls per second. Most programmers
never see this level of detail, however. Typically, application developers design programs
according to API. The API specifies a set of functions that are available to an application
programmer, including the parameters that are passed to each function and the return
values the programmer can expect.

▪ 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) that programmers are expected to use to get
operating system services.
Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ

EXAMPLE OF STANDARD API


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ System Call Example


▪ The open() system call is used in Unix/Linux to open a file and return a file descriptor.
Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Run-time Environment (RTE)

▪ Another important factor in handling system calls is the run-time environment (RTE)—the
full suite of software needed to execute applications written in a given programming
language, including its compilers or interpreters as well as other software, such as
libraries and loaders.

▪ The RTE provides a system-call interface that serves as the link to system calls made
available by the operating system.
Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ System-call interface

▪ Typically, a number associated with each system call

o System-call interface maintains a table indexed according to these numbers

▪ The system call interface invokes the 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

o Just needs to obey API and understand what OS will do as a result call

o 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)
Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ API – System Call – OS Relations


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ System Call Parameter Passing


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Parameter Passing via Table


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Types of System Calls


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Types of System Calls


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Process Control
▪ A running program needs to be able to halt its execution either normally (end()) or abnormally
(abort()).

▪ If a system call is made to terminate the currently running program abnormally, or if the program
runs into a problem and causes an error trap, a dump of memory is sometimes taken and an error
message generated. The dump is written to a special log file on disk and may be examined by a
debugger—a system program designed to aid the programmer in finding and correcting errors, or
bugs—to determine the cause of the problem.

▪ A process executing one program may want to load() and execute() another program. This
feature allows the command interpreter to execute a program as directed by, for example, a user
command or the click of a mouse.
Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Examples of Windows and Unix System Calls


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Examples of Windows and Unix System Calls


Dr. Mesut ÜNLÜ
System Calls Dr. Mesut ÜNLÜ

▪ Standard C Library Example


▪ C program invoking printf() library call, which
calls write() system call
Dr. Mesut ÜNLÜ
System Services Dr. Mesut ÜNLÜ

▪ System programs provide a convenient environment for program development and


execution. They can be divided into:
o File manipulation

o Status information sometimes stored in a File modification

o Programming language support

o Program loading and execution

o Communications

o Background services

o Application programs
Dr. Mesut ÜNLÜ
System Services Dr. Mesut ÜNLÜ

▪ File management - Create, delete, copy, rename, print, dump, list, and generally
manipulate files and directories

▪ Status information

▪ Some ask the system for info - date, time, amount of available memory, disk space,
number of users

o Others provide detailed performance, logging, and debugging information

o Typically, these programs format and print the output to the terminal or other output
devices

o Some systems implement a registry - used to store and retrieve configuration


information
Dr. Mesut ÜNLÜ
System Services Dr. Mesut ÜNLÜ

▪ File modification

o Text editors to create and modify files

o Special commands to search contents of files or perform transformations of the text

▪ Programming-language support - Compilers, assemblers, debuggers and interpreters


sometimes provided

▪ 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

o 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
Dr. Mesut ÜNLÜ
System Services Dr. Mesut ÜNLÜ

▪ Background Services
o Launch at boot time

• Some for system startup, then terminate

• Some from system boot to shutdown

o Provide facilities like disk checking, process scheduling, error logging, printing

o Run in user context not kernel context

o Known as services, subsystems, daemons


Dr. Mesut ÜNLÜ
System Services Dr. Mesut ÜNLÜ

▪ Application programs
o Don’t pertain to system

o Run by users

o Not typically considered part of OS

o Launched by command line, mouse click, finger poke


Dr. Mesut ÜNLÜ
Linkers and Loaders Dr. Mesut ÜNLÜ

▪ Usually, a program resides on disk as a binary executable file - for example, a.out or
prog.exe. To run on a CPU, the program must be brought into memory and placed in the
context of a process.

▪ Source files are compiled into object files (exe) that are designed to be loaded into any
physical memory location, a format known as an relocatable object file.

▪ The linker combines these relocatable object files into a single binary executable file.
During the linking phase, other object files or libraries may be included as well, such as
the standard C or math library.

▪ A loader is used to load the binary executable file into memory, where it is eligible to run
on a CPU core.
Dr. Mesut ÜNLÜ
Linkers and Loaders Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ
Operating-System Design and Implementation
Dr. Mesut ÜNLÜ

▪ The first problem in designing a system is to define goals and specifications. At the
highest level, the design of the system will be affected by the choice of hardware and the
type of system: traditional desktop/laptop, mobile, distributed, or real time.

▪ Beyond this highest design level, the requirements may be much harder to specify. The
requirements can, however, be divided into two basic groups:
o User goals

o 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
Dr. Mesut ÜNLÜ
Operating-System Design and Implementation
Dr. Mesut ÜNLÜ

▪ Mechanisms and Policies


o Policy: What will be done?

o 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 (example – timer)

▪ Specifying and designing an OS is highly creative task of software engineering


Dr. Mesut ÜNLÜ
Operating-System Design and Implementation
Dr. Mesut ÜNLÜ

▪ Implementation

▪ Once an operating system is designed, it must be implemented. Because operating


systems are collections of many programs, written by many people over a long period of
time, it is difficult to make general statements about how they are implemented.

▪ Much variation

o Early OSes in assembly language

o Then system programming languages like Algol, PL/1

o Now C, C++
Dr. Mesut ÜNLÜ
Operating-System Design and Implementation
Dr. Mesut ÜNLÜ

▪ Implementation

▪ Actually usually a mix of languages

o Lowest levels in assembly

o Main body in C

o Systems programs in C, C++, scripting languages like PERL, Python, shell scripts

▪ More high-level language easier to port to other hardware

o But slower

▪ Emulation can allow an OS to run on non-native hardware


Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ A system as large and complex as a modern operating system must be engineered


carefully if it is to function properly and be modified easily.

▪ Various ways to structure ones

o Simple structure - MS-DOS

o More complex - UNIX

o Layered - an abstrcation

o Microkernel - Mach
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Monolithic Structure

▪ The simplest structure for organizing an operating system is no structure at all. That is,
place all of the functionality of the kernel into a single, static binary file that runs in a
single address space. This approach - known as a monolithic structure - is a common
technique for designing operating systems.

▪ An example of such limited structuring is the original UNIX operating system, which
consists of two separable parts: the kernel and the system programs. The kernel is further
separated into a series of interfaces and device drivers, which have been added and
expanded over the years as UNIX has evolved.
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Monolithic Structure

Traditional UNIX system structure


Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Monolithic Structure

▪ UNIX - limited by hardware functionality, the original UNIX operating system had limited
structuring. The UNIX OS consists of two separable parts

o Systems programs

o 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
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Monolithic Structure

▪ The Linux operating system is based on


UNI. Applications typically use the glibc
standard C library when
communicating with the system call
interface to the kernel.

▪ The Linux kernel is monolithic in that


it runs entirely in kernel mode in a
single address space.

Linux system structure


Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Layered Approach

▪ The monolithic approach is often known as a tightly coupled system because changes to
one part of the system can have wide-ranging effects on other parts.

▪ A loosely coupled system: A system is divided into separate, smaller components that have
specific and limited functionality. All these components together comprise the kernel. The
advantage of this modular approach is that changes in one component affect only that
component.
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Layered Approach

▪ 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
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Microkernels

▪ This method structures the operating system by removing all nonessential components from
the kernel and implementing them as user level programs that reside in separate address
spaces. The result is a smaller kernel. There is little consensus regarding which services
should remain in the kernel and which should be implemented in user space.

▪ The main function of the microkernel is to provide communication between the client program
and the various services that are also running in user space. Communication is provided
through message passing.
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Microkernels

Application File Device user


Program System Driver mode

messages messages

Interprocess memory CPU kernel


Communication managment scheduling mode

microkernel

hardware
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Microkernels

▪ Benefits:

o Easier to extend a microkernel

o Easier to port the operating system to new architectures

o More reliable (less code is running in kernel mode)

o More secure

▪ Detriments:

o Performance overhead of user space to kernel space communication


Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Modules

▪ Many modern operating systems implement loadable kernel modules

o Uses object-oriented approach

o Each core component is separate

o Each talks to the others over known interfaces

o Each is loadable as needed within the kernel

▪ Overall, similar to layers but with more flexible

o Linux, Solaris, etc


Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Solaris Modular Approach


Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Hybrid Systems

▪ In practice, very few operating systems adopt a single, strictly defined structure. Instead, they
combine different structures, resulting in hybrid systems that address performance, security,
and usability issues.

▪ Most modern operating systems are actually not one pure model

o Hybrid combines multiple approaches to address performance, security, usability needs

o Linux and Solaris kernels in kernel address space, so monolithic, plus modular for dynamic
loading of functionality

o Windows mostly monolithic, plus microkernel for different subsystem personalities


Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Hybrid Systems

▪ macOS and iOS graphical user interface


Aqua

▪ Apple Mac OS X hybrid, layered, Aqua application environments and services

UI plus Cocoa programming Java Cocoa Quicktime BSD

environment
kernel environment

o Below is kernel consisting of Mach BSD

microkernel and BSD Unix parts, Mach

plus I/O kit and dynamically


I/O kit kernel extensions
loadable modules (called kernel
Mac OS X Structure
extensions)
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Hybrid Systems

▪ macOS and iOS

▪ Apple mobile OS for iPhone, iPad

o Structured on Mac OS X, added functionality

o Does not run OS X applications natively


• Also runs on different CPU architecture (ARM vs. Intel)

o Cocoa Touch Objective-C API for developing apps

o Media services layer for graphics, audio, video


Architecture of Apple’s macOS and
o Core services provides cloud computing, databases iOS operating systems

o Core operating system, based on Mac OS X kernel


Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Hybrid Systems

▪ Android
o Developed by Open Handset Alliance (mostly Google)

• Open Source

o Similar stack to IOS

o Based on Linux kernel but modified

• Provides process, memory, device-driver management

• Adds power management


Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Hybrid Systems

▪ Android
o Runtime environment includes core set of libraries and Dalvik virtual machine

• Apps developed in Java plus Android API


➢ Java class files compiled to Java bytecode then translated to executable than runs in
Dalvik VM

o Libraries include frameworks for web browser (webkit), database (SQLite), multimedia,
smaller libc
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ

▪ Hybrid Systems

▪ Android
Dr. Mesut ÜNLÜ
Building and Booting an Operating System Dr. Mesut ÜNLÜ

▪ Operating-System Generation

▪ If you are generating (or building) an operating system from scratch, you must follow
these steps:
Dr. Mesut ÜNLÜ
Building and Booting an Operating System Dr. Mesut ÜNLÜ

▪ System Boot
▪ When power initialized on system, execution starts at a fixed memory location

o Firmware ROM used to hold initial boot code

▪ Operating system must be made available to hardware so hardware can start it

o Small piece of code – bootstrap loader, stored in ROM or EEPROM locates the kernel, loads it
into memory, and starts it

o Sometimes two-step process where boot block at fixed location loaded by ROM code, which loads
bootstrap loader from disk

▪ Common bootstrap loader, GRUB, allows selection of kernel from multiple disks, versions, kernel
options (Linux and UNIX systems)

▪ Kernel loads and system is then running


Dr. Mesut ÜNLÜ
Dr. Mesut ÜNLÜ

You might also like