You are on page 1of 37

0

Operating Systems
Lecture 2 :
Operating System
Structures

Dr. Essam Halim Houssein


Lecturer, Faculty of Computers and Informatics,
Benha University
2

2-1 Operating System Services

An operating system provides an environment for the

execution of programs. It provides certain services to programs and

to the users of those programs. The specific services provided, of course,

differ from one operating system to another, but we can identify common

classes. These operating system services are provided for the convenience

of the programmer, to make the programming task easier. Figure 2.1

shows one view of the various operating system services and how they

interrelate.
3
4

One set of operating system services provides


functions that are helpful to the user.

1. User interface. Almost all operating systems have a User Interface

(UI). This interface can take several forms. One is a common line

interface (CLI), which uses text commands and a method for entering

them (say, a program to allow entering and editing of commands).

Another is a batch interface in which commands and directives to

control those commands are entered into files, and those files are

executed. Most commonly, a graphical user interface (GUI) is used.


5

2. Program execution. The system must be able to load a program

into memory and to run that program. The program must be able to

end its execution, either normally or abnormally (indicating error).


6

3. 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 recording to a CD or DVD drive or blanking a

display screen). For efficiency and protection, users usually cannot

control I/O devices directly. Therefore, the operating system must

provide a means to do I/O.


7

4. File-system manipulation. The file system is of particular

interest. Obviously, programs need to read and write files and

directories. They also need to create and delete them by name, search

for a given file, and list file information. Finally, some programs

include permissions management to allow or deny access to files or

directories based on file ownership. Many operating systems provide a

variety of file systems, sometimes to allow personal choice, and

sometimes to provide specific features or performance characteristics.


8

5. Communications. There are many circumstances in which one

process needs to exchange information with another process. Such

communication may occur between processes that are executing on the

same computer or between processes that are executing on different

computer systems tied together by a computer network.

Communications may be implemented via shared memory or through

message passing, in which packets of information are moved between

processes by the operating system.


9

6. Error detection. The operating system needs to be constantly


aware of possible errors. Errors may occur in the CPU and memory
hardware (such as a memory error or a power failure), in I/O devices
(such as a parity error on tape, a connection failure on a network, or
lack of paper in the printer), and in the user program (such as an
arithmetic overflow, an attempt to access an illegal memory location,
or a too-great use of CPU time). For each type of error, the operating
system should take the appropriate action to ensure correct and
consistent computing. Of course, there is variation in how operating
systems react to and correct errors. Debugging facilities can greatly
enhance the user's and programmer's abilities to use the system
efficiently.
10

Another set of operating system functions exists not for

helping the user but rather for ensuring the efficient operation

of the system itself. Systems with multiple users can gain

efficiency by sharing the computer resources among the users.


11

1. Resource allocation. When there are a multiple users or multiple


jobs running at the same time, resources must be allocated to each of
them. Many different types of resources are managed by the operating
system. Some (such as CPU cycles, main memory, and file storage)
may have special allocation code, whereas others (such as I/O devices)
may have much more general request and release code. For instance,
in determining how best to use the CPU, operating systems have CPU-
scheduling routines that take into account the speed of the CPU, the
jobs that must be executed, the number of registers available, and
other factors. There may also be routines to allocate printers, modems,
USB storage drives, and other devices.
12

2. Accounting. We want to keep track of which users use how much

and what kinds of computer resources. This record keeping may be

used for accounting or simply for accumulating usage statistics.

Usage statistics may be a valuable tool for researchers who wish to

reconfigure the system to improve computing services.


13

3. Protection and security. The owners of information stored in a


multiuser or networked computer system may want to control use of
that information. When several separate processes execute
concurrently, it should not be possible for one process to interfere with
the others or with the operating system itself. Protection involves
ensuring that all access to system resources controlled.
Security of the system from outsiders is also important. Such security
starts with requiring each user to authenticate himself or herself to the
system, usually by means of a password, to gain access to system
resources. It extends to defending external I/O devices,
14

2-3 System calls

System calls provide an interface to the services made available

by an operating system. These calls are generally available as routines

written in C and C++, although certain low-level tasks (for example, tasks

where hardware must be accessed directly), may need to be written using

assembly-language instructions.
15
16

writing a simple program to read data from one file and copy
them to another file.
17

System calls can be grouped roughly into six major categories:

process control, file manipulation, device manipulation, information

maintenance, communication , and protection.


18

Process control

o end, abort

o load, execute

o create process, terminate process

o get process attributes, set process attributes

o wait for time

o wait event, signal event

o allocate and free memory


19

File management

o create file, delete file

o open, close

o read, write, reposition

o get file attributes, set file attributes


20

Device management

o request device, release device

o read, write, reposition

o get device attributes, set device attributes

o logically attach or detach devices


21

Information maintenance

o get time or date, set time or date

o get system data, set system data

o get process, file, or device attributes

o set process, file, or device attributes


22

Communications

o create, delete communication connection

o send, receive messages

o transfer status information

o attach or detach remote devices


23
24
25

System Programs
• System programs provide a convenient environment for
program development and execution. Some of them are simply
user interfaces to system calls. Others are considerably more complex.
They can be divided into:
▫ File manipulation
▫ Status information
▫ File modification
▫ Programming language support
▫ Program loading and execution
▫ Communications
▫ Application programs

• Most users’ view of the operating system is defined by system


programs, not the actual system calls
26

System Programs (Cont.)


• 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
• Others provide detailed performance, logging, 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
27

System Programs (Cont.)


• 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, 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
28

Virtual Machines (Task 2)?

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.
29
30

There are several reasons for creating a virtual

machine. Most of them are fundamentally related to being able to

share the same hardware yet run several different execution

environments (that is, different operating systems) concurrently.


31

Virtual Machines

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

• A virtual machine provides an interface identical to the


underlying hardware.

• 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.
32

Operating-System Debugging
• Debugging is finding and fixing errors, or bugs
• OS 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.”
33

System Boot

Booting: The procedure of starting a computer by loading the kernel

is known as booting the system. On most computer systems, a small

piece of code known as the bootstrap program or bootstrap loader

locates the kernel, loads it into main memory, and starts its execution.

Some computer systems, such as PCs, use a two-step process in which a

simple bootstrap loader fetches a more complex boot program from disk,

which in turn loads the kernel.

Firmware used to hold initial boot code


34

Operating System Design and Implementation (Task 1)?

• Design and Implementation of OS not “solvable”, but some approaches


have proven successful

• Internal structure of different Operating Systems can vary widely

• Start by defining goals and specifications

• Affected by choice of hardware, type of system

• User goals and 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
35

Operating System Design and Implementation (Cont.)

• Important principle to separate


• Policy: What will be done?
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
36

Task:
Task (1) : OS Design and Implementation ch2
Task (2) : Java Program Forking Separate Process? ch3
Task (3) : Sockets in Java? ch3
Task (4) : Threads? ch4
Task (5) : Pthreads? ch4
Task (6) : Process Synchronization? ch5
Task (7) : Protection? ch14
Task (8) : Linux Protection?
Task (9) : Windows Protection?
Task (10) : Security? ch15
Any Questions?

We wish you the very best of luck in your study of operating systems.

You might also like