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

Operating System Structure

The document provides an overview of operating system services, including user interfaces, system calls, and resource management. It details the functions of system calls, the role of APIs, and how system calls interact with the OS kernel. Additionally, it covers process control, file management, device management, and communication methods within operating systems.

Uploaded by

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

Operating System Structure

The document provides an overview of operating system services, including user interfaces, system calls, and resource management. It details the functions of system calls, the role of APIs, and how system calls interact with the OS kernel. Additionally, it covers process control, file management, device management, and communication methods within operating systems.

Uploaded by

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

 Operating System Services

 User Operating System Interface


 System Calls
 Types of System Calls
 System Programs
 Operating System Design and Implementation
 Operating System Structure
 Virtual Machines
 Operating System Debugging
 Operating System Generation
 System Boot
 To describe the services an operating system provides to
users, processes, and other systems.

 To discuss the various ways of structuring an operating


system.

 To explain how operating systems are installed and


customized and how they boot.
 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.
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.
 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 - 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.

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

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

 If a system is to be protected and secure, precautions must


be instituted throughout it. A chain is only as strong as its
weakest link.
Command Line Interface (CLI) or command interpreter allows
direct command entry.

 Sometimes implemented in kernel, sometimes by systems


program.

 Sometimes multiple flavors implemented – shells.

Primarily fetches a command from user and executes it.


 Sometimes commands built-in, sometimes just names of
programs.

 If the latter, adding new features doesn’t require shell


modification.
 User-friendly desktop metaphor interface
◦ 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.
 Many systems now include both CLI and GUI interfaces
◦ Microsoft Windows is GUI with CLI “command” shell.
◦ Apple MacOS X as “Aqua” GUI interface with UNIX kernel
underneath and shells available.
◦ Solaris is CLI with optional GUI interfaces (Java Desktop, KDE).
What is a System Call?

▪ A system call is a method for a computer program to request a


service from the kernel of the Operating System.

▪ A system call is a method of interacting with the Operating


System via programs.

▪ Typically written in a high-level language (C or C++).

▪ The kernel system can only be accessed using system calls.

▪ System calls are required for any programs that use


resources.

▪ Each OS has its own name for each System Call.


 System calls are mostly accessed by programs via a high-level
Application Program Interface (API) rather than direct system call use.

 The Application Program Interface (API) connects the Operating


System's functions to user programs. It acts as a link between the
Operating System and a process, allowing user-level programs to
request Operating System services.

 API specifies a set of functions that are available to an application


programmer.

 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).
Why use APIs rather than system calls?
 Underlying systems calls (error codes) can be more
complicated.

 API gives a uniform, portable interface.

 One need not remember I/O registers or order of I/O


operation.

 API lets the OS manage the requests so your software is less


likely to affect other software when it crashes.

 There are many APIs. They simply system calls,


implement cross-platform interface so you can port the app,
manage access to secure areas, and do many other useful
things.
How are system calls made?

• When a computer software needs to access the operating


system's kernel, it makes a system call. The system call uses
an API to expose the operating system's services to user
programs.

• It is the only method to access the kernel system. All


programs or processes that require resources for execution
must use system calls, as they serve as an interface between
the operating system and user programs.
Below are some examples of how a system call varies from a
user function.

1. A system call function may create and use kernel processes to


execute the asynchronous processing.

2. A system call has greater authority than a standard


subroutine. A system call with kernel-mode privilege
executes in the kernel protection domain.

3.System calls are not permitted to use shared libraries or any


symbols that are not present in the kernel protection domain.

4. The code and data for system calls are stored in global
kernel memory.
Why do you need system calls in Operating System?

There are various situations where you must require system calls
in the operating system. Following of the situations are as follows:

• It is must require when a file system wants to create or delete a


file.

• Network connections require the system calls to sending and


receiving data packets.

• If you want to read or write a file, you need to system calls.

• If you want to access hardware devices, including a printer,


scanner, you need a system call.

• System calls are used to create and manage new processes.


 System call sequence to copy the contents of one file to another
file.
 read(fd,buffer,nbytes)
 Consider the ReadFile() function in the
Win32 API—a function for reading from a file.

 A description of the parameters passed to ReadFile()


◦ HANDLE file—the file to be read.
◦ LPVOID buffer—a buffer where the data will be read into and written from.
◦ DWORD bytesToRead—the number of bytes to be read into the buffer.
◦ LPDWORD bytesRead—the number of bytes read during the last read.
◦ LPOVERLAPPED ovl—indicates if overlapped I/O is being used.
 C program invoking printf() library call, which calls write() system call
 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)
Often, more information is required than simply identity of desired
system call.
Exact type and amount of information vary according to OS and
call.
Three general methods used to pass parameters to the OS
Simplest: pass the parameters in registers.
 In some cases, may be more parameters than 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.
How System Calls Work

• The Applications run in an area of memory known as user space.

• A system call connects to the operating system's kernel, which executes


in kernel space.

• When an application creates a system call, it must first obtain permission


from the kernel. It achieves this using an interrupt request, which pauses
the current process and transfers control to the kernel.

• If the request is permitted, the kernel performs the requested action, like
creating or deleting a file. As input, the application receives the kernel's
output.

• The application resumes the procedure after the input is received.

• When the operation is finished, the kernel returns the results to the
application and then moves data from kernel space to user space in
memory.
How System Calls Work

• A simple system call may take few nanoseconds to provide


the result, like retrieving the system date and time.

• A more complicated system call, such as connecting to a


network device, may take a few seconds. Most operating
systems launch a distinct kernel thread for each system call
to avoid bottlenecks.

• Modern operating systems are multi-threaded, which means


they can handle various system calls at the same time.
Some Win32 API calls
Process control
File management
Device management
Information maintenance
Communications
• Process Control
Process control is the system call that is used to direct the
processes. Some process control examples include creating process , load,
abort, end, execute,, terminate the process, Wait for time, Wait event,
Signal event etc.

• When one process pauses or stops, then another must be launched or


resumed.

• If we create a new process, we should be able to control its execution.

• This control requires the ability to determine and reset the process
attributes like process priority, its maximum allowable execution time
etc. are set and retrieved by OS.

• After creating the new process, the parent process may have to wait
(wait time), or wait for an event to occur(wait event).

• The process sends back a signal when the event has occurred (signal
event).
In DOS, the command interpreter loaded first. Then loads the process and
transfers control to it. The interpreter does not resume until the process has
completed, as shown in Figure.

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


UNIX is a multi-tasking system, the command interpreter
remains completely resident when executing a process, as
shown in Figure below.
• The user can switch back to the command interpreter at
any time, and can place the running process in the
background even if it was not originally launched as a
background process.

• In order to do this, the command interpreter first executes a


"fork" system call, which creates a second process which is
an exact duplicate (clone ) of the original command
interpreter.

• The original process is known as the parent, and the


cloned process is known as the child, with its own unique
process ID and parent ID.
• The child process then executes an "exec" system call,
which replaces its code with that of the desired process.

• The parent (command interpreter) normally waits for


the child to complete before issuing a new command
prompt, but in some cases it can also issue a new prompt
right away, without waiting for the child process to
complete. (The child is then said to be running "in the
background", or "as a background process" ).
fork()
fork() System call to create a child process.

The syntax used for the fork system call is


pid_t fork(void);

Fork system call creates a child that differs from its parent
process only in pid(process ID) and ppid(parent process ID).
Resource utilization is set to zero.

Return values:- PID (process ID) of the child process is


returned in parents thread of execution and “zero” is returned
in child’s thread of execution.

The fork() returns the PID of the child process. If the value is
non-zero, then it is parent process's id, and if this is 0, then
this is child process's id.
wait()
wait() system call suspends execution of current process until a
child has exited or until a signal has delivered whose action is
to terminate the current process or call signal handler.

The syntax used for the fork system call is

pid_t wait(int * status);

waitpid(): suspends execution of current process until a child


as specified by pid arguments has exited or until a signal is
delivered.

pid_t waitpid (pid_t pid, int *status, int options);


exec()
exec() family of functions or sys calls replaces current process
image with new process image.

There are functions like execl, execlp,execle,execv, execvp and


execvpe are used to execute a file.

These functions are combinations of array of pointers to null


terminated strings that represent the argument list , this will
have path variable with some environment variable
combinations.

exit()

This function is used for normal process termination. The status


of the process is captured for future reference.
• File Management
File management is a system call that is used to handle the
files. Some file management examples include creating files,
delete files, open, close, read, write, get file attributes, set device
attributes etc.

The file management functions of OS are –


• After creating a file, the file is opened. Data is read or
written to a file.

• The file pointer may need to be repositioned to a point.

• The file attributes like filename, file type, permissions, etc.


are set and retrieved using system calls.

• These operations may also be supported for directories as


well as ordinary files.
• Device Management
Device management is a system call that is used to deal with
devices. Some examples of device management include read, request
device, write, get device attributes, release device, reposition, and
logically attach or detach devices. etc.

• When a process needs a resource, a request for resource is done.


Then the control is granted to the process. If requested resource is
already attached to some other process, the requesting process
has to wait.

• In multiprogramming systems, after a process uses the device, it


has to be returned to OS, so that another process can use the
device.

• Devices may be physical ( e.g. disk drives ), or virtual / abstract (


e.g. files, partitions, and RAM disks ).
• Information Maintenance
Information maintenance is a system call that is used to
maintain information.
There are some examples of information maintenance,
including getting system data, set time or date, get time or
date, set system data, get process file/device attributes, set
process file/device attributes, etc.

These system calls care used to transfer the information


between user and the OS.

Information like current time & date, no. of current users,


version number of OS, amount of free memory, disk space
etc. are passed from OS to the user.
• Communication
Communication is a system call that is used for
communication. There are some examples of communication
including
create, delete communication connections, send,
receive messages,
transfer status information,attach/detach remote
devices etc.

There are two models of interprocess communications:

1. message passing model.

2. Shared-memory model.
1.The message passing model must support calls to:
The communicating processes exchange messages with one another to
transfer information.

Messages can be exchanged between the processes either directly or


indirectly through common mailbox. Before communication conection must be
opened.

• Identify a remote process and/or host with which to communicate.

• Establish a connection between the two processes.

• Open and close the connection as needed.

• Transmit messages along the connection.

• Wait for incoming messages, in either a blocking or non-blocking state.

• Delete the connection when no longer needed.


The shared memory model must support calls to:

• Create and access memory that is shared amongst processes (and


threads. )

• Free up shared memory and/or dynamically allocate it as needed.

• Message passing is simpler and easier, (particularly for inter-computer


communications), and is generally appropriate for small amounts of data. It
is easy to implement, but there are system calls for each read and write
process.

• Shared memory is faster, and is generally the better approach where large
amounts of data are to be shared.

• This model is difficult to implement, and it consists of only few system calls.
System programs provide a convenient environment for
program development and execution.

System programs also provide a bridge between the user


interface and system calls.

Most users’ view of the operation system is defined by system


programs, not the actual system calls. Because system
programs are closer to the user interface.

Some of them are simply user interfaces to system calls; In


reality, they are much more complex.
For example, a compiler is a complex system program.
Purpose of using system program

System programs communicate and coordinate the activities


and functions of hardware and software of a system and also
controls the operations of the hardware.

An operating system is one of the examples of system


software. Operating system controls the computer
hardware and acts like an interface between the
application software’s.
An image that describes system programs in the operating
system hierarchy is as follows −
System programs can be divided into:

File manipulation

Status information

File modification

Programming language support

Program loading and execution

Communications

Application programs
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 , processes
running, data logging, etc.

Others provide detailed performance and debugging


information.

Typically, these programs format and print the output to the


terminal or other output devices.

Some systems implement a registry - used to store and


retrieve configuration information for particular applications.
File modification-Text editors to create and modify files.
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.
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.
Design and Implementation of OS not “solvable”, but
some approaches have proven successful.

Internal structure of different Operating Systems can


vary widely.

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: batch, time shared, single user, multiuser,
distributed, real time, or general purpose.
Beyond this highest design level, the requirements may be
much harder to specify.

The requirements can, however, be divided into two basic


groups.
User goals (User requirements)
System goals (system requirements)
▪ 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.
Policies determine what is to be done.
Mechanisms determine how it is to be implemented.
Example: In timer- counter and decrementing counter is the
mechanism and deciding how long the time has to be set is the
policies.

Policies change overtime. In the worst case, each change in


policy would require a change in the underlying mechanism.

If properly separated and implemented, policy changes can be


easily adjusted without re- writing the code, just by adjusting
parameters or possibly loading new data / configuration files.
The separation of policy from mechanism is a very important
principle, it allows maximum flexibility if policy decisions are to
be changed later.
Implementation
• Traditionally OS were written in assembly language.

• In recent years, OS are written in C, or C++. Critical sections of


code are still written in assembly language.

• The first OS that was not written in assembly language was the
Master Control Program (MCP).

• The advantages of using a higher-level language for


implementing operating systems are: The code can be written
faster, more compact, easy to port to other systems and is easier
to understand and debug.

• The only disadvantages of implementing an operating system in


a higher-level language are reduced speed and increased
storage requirements.
• Many operating systems do not have well-defined structures.

• They started as small, simple, and limited systems and then grew
beyond their original scope. Eg: MS-DOS.

• In MS-DOS, the interfaces and levels of functionality are not well


separated.

• Application programs can


access basic I/O routines to
write directly to the display and
disk drives.

• Such freedom leaves MS-DOS


in bad state and the entire
system can crash down when
user programs fail.
Figure: MS-DOS layer structure.
• Another example of limited structuring is the original UNIX
OS.

• UNIX initially was limited by hardware functionality.

• UNIX OS consists of two separable parts:


The kernel
The system programs.

• The kernel is further


separated into a series of
interfaces and device drivers.

• The kernel provides the file


system, CPU scheduling,
memory management,
and other operating-system
functions through system
calls.
• The OS is broken into number of layers (levels).

• Each layer rests on the layer below it, and relies on the services
provided by the next lower layer.

• Bottom layer (layer 0) is the hardware and the topmost layer is the
user interface.
• A typical layer, consists of data
structure and routines that can be
invoked by higher-level layer.

• With modularity, layers are


selected such that each uses
functions (operations) and
services of only lower-level
layers.
Advantage of layered approach:

Is simplicity of construction and debugging.

• The layers are selected so that each uses functions and


services of only lower-level layers. So simplifies debugging and
system verification.

• The layers are debugged one by one from the lowest and if any
layer doesn’t work, then error is due to that layer only, as the
lower layers are already debugged. Thus the design and
implementation is simplified.

A layer need not know how its lower level layers are implemented.
Thus hides the operations from higher layers.
Disadvantages of layered approach:

• The various layers must be appropriately defined, as a layer


can use only lower level layers.

• Less efficient than other types, because any interaction


with layer 0 required from top layer. The system call
should pass through all the layers and finally to layer 0.
This is an overhead.
• This method structures the operating system by removing
all nonessential components from the kernel and
implementing them as system and user-level programs
thus making the kernel as small and efficient as possible.

• The removed services are implemented as system


applications.

• Most microkernels provide basic process and memory


management, and message passing between other
services.

• The main function of the microkernel is to provide a


communication facility between the client program and the
various services that are also running in user space.
 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.
 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.

A set of modules which can be linked in dynamically.

 Overall, similar to layers but with more flexible.

 But any module is free to contact any other module,


eliminating the problems of going through multiple
intermediary layers.
Eg: Solaris, Linux and MacOSX.
Solaris Modular Approach
Virtual Machines
• The fundamental idea behind a virtual machine is to
abstract the hardware of a single computer (the CPU, memory,
disk drives, network interface cards, and so forth) into several
different execution environments, thereby creating the illusion that
each separate execution environment is running its own private
computer.

• Creates an illusion that a process has its own


processor with its own memory.

• 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.
Virtual Machines
 A virtual machine provides an interface identical to the
underlying bare hardware.

 Host OS is the main OS installed in system and the other


OS installed in the system are called guest OS.

 The operating system host creates the illusion that a process


has its own processor and (virtual memory).

 Each guest provided with a (virtual) copy of underlying


computer.

 First appeared commercially in IBM mainframes in 1972.

 Fundamentally, multiple execution environments (different


operating systems) can share the same hardware.
Virtual Machines

(a) Non-virtual machine (b) virtual machine


Virtual Machines
How does a virtual machine work?
➢ Virtualization is the process of creating a software-based or "virtual"
version of a computer, with dedicated amounts of CPU, memory and
storage that are "borrowed" from a physical host computer
—such as your personal computer.
— and/or a remote server.
—such as a server in a cloud
provider's datacenter.

➢ A virtual machine is a computer file, typically called an image, which


behaves like an actual computer. It can run in a window as a separate
computing environment, often to run a different operating system—or even
to function as the user's entire computer experience—as is common on
many people's work computers.

➢ The virtual machine is partitioned from the rest of the system, meaning
that the software inside a VM cannot interfere with the host computer's
primary operating system.
What are VMs used for?

• Building and deploying apps to the cloud.

• Trying out a new operating system (OS), including beta


releases.

• Spinning up a new environment to make it simpler and quicker


for developers to run dev-test scenarios.

• Backing up your existing OS.

• Accessing virus-infected data or running an old application by


installing an older OS.

• Running software or apps on operating systems that they were


not originally intended for.
Because of their flexibility and portability, virtual machines
provide many benefits, such as:

Cost savings—running multiple virtual environments from one piece


of infrastructure means that you can drastically reduce your physical
infrastructure footprint.

This boosts your bottom line—decreasing the need to maintain


nearly as many servers and saving on maintenance costs and
electricity.

Agility and speed—Spinning up a VM is relatively easy and quick


and is much simpler than provisioning an entire new environment for
your developers. Virtualization makes the process of running dev-test
scenarios a lot quicker.

Lowered downtime—VMs are so portable and easy to move from


one hypervisor to another on a different machine—this means that
they are a great solution for backup, in the event the host goes down
unexpectedly.
Scalability—VMs allow you to more easily scale your apps by
adding more physical or virtual servers to distribute the workload
across multiple VMs. As a result you can increase the availability
and performance of your apps.

Security benefits— Because virtual machines run in multiple


operating systems, using a guest operating system on a VM allows
you to run apps of questionable security and protects your host
operating system.

VMs also allow for better security forensics and are often used to
safely study computer viruses, isolating the viruses to avoid risking
their host computer.

Ex: Azure VMs


Window VMs
Linux VMs
The Java Virtual Machine
Operating-System Debugging
Debugging is finding and fixing errors, or bugs.
OSes generate log files containing error information.

Failure of an application can generate core dump file capturing


memory of the process.

Operating system failure can generate crash dump file containing


kernel memory.

Beyond crashes, performance tuning can optimize system


performance.

Kernighan’s Law: “Debugging is twice as hard as writing the code in


the first place. Therefore, if you write the code as cleverly as
possible, you are, by definition, not smart enough to debug it.”
Operating System Generation

• Operating systems are designed to run on any of a class of


machines; the system must be configured for each specific
computer site.

• SYSGEN program obtains information concerning the specific


configuration of the hardware system.

• Booting – starting a computer by loading the kernel.

• Bootstrap program – code stored in ROM that is able to locate


the kernel, load it into memory, and start its execution.
System Boot

• Operating system must be made available to hardware so


hardware can start it.

• Small piece of code – bootstrap loader, locates the kernel,


loads it into memory, and starts it.

• Sometimes two-step process where boot block at fixed


location loads bootstrap loader.

• When power initialized on system, execution starts at a fixed


memory location- Firmware used to hold initial boot code.

You might also like