Operating-System Structures
Operating-System Structures
Mesut ÜNLÜ
Dr. Mesut ÜNLÜ
Operating-System Structures
1
Dr. Mesut ÜNLÜ
Operating-System Structures Dr. Mesut ÜNLÜ
▪ System Calls
▪ System Programs
▪ 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).
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.
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
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
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Ü
o Let's write a script prompting user to enter two numbers and to find the greatest
and sum of the given numbers.
• https://www.onlinegdb.com/online_bash_shell
Dr. Mesut ÜNLÜ
User and Operating-System Interfaces Dr. Mesut ÜNLÜ
• Start website-address
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.
• 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Ü
o Touch-Screen Interface
• Voice commands.
▪ 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.
▪ 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.
▪ 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Ü
cp in.txt out.txt
▪ 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Ü
▪ 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
▪ 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
• Managed by run-time support library (set of functions built into libraries included with
compiler)
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Ü
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 Typically, these programs format and print the output to the terminal or other output
devices
▪ File modification
▪ 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
o Provide facilities like disk checking, process scheduling, error logging, printing
▪ Application programs
o Don’t pertain to system
o Run by users
▪ 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Ü
▪ 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)
▪ Implementation
▪ Much variation
o Now C, C++
Dr. Mesut ÜNLÜ
Operating-System Design and Implementation
Dr. Mesut ÜNLÜ
▪ Implementation
o Main body in C
o Systems programs in C, C++, scripting languages like PERL, Python, shell scripts
o But slower
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
▪ 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
▪ 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
▪ 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
messages messages
microkernel
hardware
Dr. Mesut ÜNLÜ
Operating-System Structure Dr. Mesut ÜNLÜ
▪ Microkernels
▪ Benefits:
o More secure
▪ Detriments:
▪ Modules
▪ 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 Linux and Solaris kernels in kernel address space, so monolithic, plus modular for dynamic
loading of functionality
▪ Hybrid Systems
environment
kernel environment
▪ Hybrid Systems
▪ Hybrid Systems
▪ Android
o Developed by Open Handset Alliance (mostly Google)
• Open Source
▪ Hybrid Systems
▪ Android
o Runtime environment includes core set of libraries and Dalvik virtual machine
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 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)