Sie sind auf Seite 1von 36

Operating-System Services

2.2
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Operating System Services
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.
2.3
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
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 users and
programmers abilities to efficiently use the system
2.4
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
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 - Some (such as CPU cycles,mainmemory,
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.
2.5
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
User Operating System Interface - CLI
CLI 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 doesnt require shell
modification
2.6
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
User Operating System Interface - GUI
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 Mac OS X as Aqua GUI interface with UNIX kernel
underneath and shells available
Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)

Processes
2.8
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Concept
Process a program in execution; process execution must
progress in sequential fashion

are active entities which executed in sequential
fashion.
A program residing on your disk will only be named a
process when it already demands execution.
is more than the program code. It also includes the
current state, activity and other relevant information.

*Operating system processes execute system code and user
processes execute user code.
2.9
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process State
As a process executes, it changes state
new: The process is being created
running: Instructions are being executed
waiting: The process is waiting for some event to
occur
ready: The process is waiting to be assigned to a
processor
terminated: The process has finished execution
2.10
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Diagram of Process State
2.11
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process State
Transitions:
dispatch transition from READY to RUNNING. This is the
assignment of the CPU to the process.
block (I/O or event wait)transition from RUNNING to
WAITING. This happens when a process voluntarily
relinquishes control of the CPU due to some event.
wakeup (I/O or event completion) transition from
WAITING to READY. This happens when the event being
waited by a process occurs, e.g. I/O completion.
preempt (interrupt) transition from RUNNING to READY.
This happens when a process is forced out of the CPU
because a higher priority job is ready to take control of the
CPU or in time-sharing systems the process consumes its
time share.
2.12
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Control Block (PCB)
Each process is represented in the OS by its own process
control block (PCB)
PCB a record containing many pieces of information
associated with a specific process.
Information associated with each process
Process state
Program counter
CPU registers
CPU scheduling information
Memory-management information
Accounting information
I/O status information

2.13
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Control Block (PCB)
Process State
defines the current activity of the process.
state may be new, ready, waiting, blocked, or halted.
Program counter
indicates the address of the next instruction to be executed for
this purpose.
CPU Register
the values of the registers must be saved when an interrupt
occurs to ensure that the process can progress afterwards.
CPU scheduling information
This information contains various scheduling parameters and
details. e.g. process priority.
Accounting information
this includes the information like amount of CPU used, time limits,
and so on.
I/O status information
This would consist of the list of resources allocated to the
process.
2.14
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Control Block (PCB)
PCB- simply acts as a repository for any information
that may vary form process to process.
2 characteristics of process:
1. execution process state, program counter,
scheduling
2. ownership memory management, and
resource management.

2.15
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Control Block (PCB)
2.16
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
CPU Switch From Process to Process
2.17
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Threads
A process is a program that performs a single THREAD
of execution.

a basic unit of CPU utilization( basic unit of execution).
lightweight process
consists of program counter, a register set and a stack
space.
operate like processes in many aspects. ( has several
states, executes in sequential fashion, can use CPU at a
time)
are not independent of one another.
designed to aid one another.

2.18
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Threads
Multithreading
the ability of an operating system to support multiple threads
of execution within a single process.
Ex. Java run-time environment, windows 2000, Solaris,
Linux and OS/2.
Advantages of multithreading:
1.Expensive context switching in traditional processes is avoided
since there is an extensive sharing of resources among peer
threads.
2. It takes a far less time to create a new thread in an existing
process than to create a brand new process.
3.It takes less time to terminate a thread than a process.
4.Threads enhance efficient communication between different
executing programs.
2.19
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Scheduling
Question: How do we run processes concurrently if we
only have one CPU?
Answer: Process Scheduling (by having an order of
execution )
Scheduling Queues:
Job queue set of all processes in the system
Ready queue set of all processes residing in main
memory, ready and waiting to execute
Device queues set of processes waiting for an I/O
device. Each device has its own device queue.

Processes migrate among the various queues
2.20
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Ready Queue And Various I/O Device Queues
2.21
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Representation of Process Scheduling
Queueing Diagram
Rectangular box- queue
Circle-resources
Arrows- flow of processes
2.22
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Schedulers
A process migrates between the various scheduling
queues throughout its lifetime.

Long-term scheduler (or job scheduler) selects which
processes should be brought into the ready queue
Short-term scheduler (or CPU scheduler) selects
which process should be executed next and allocates
CPU
2.23
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Schedulers (Cont.)
Short-term scheduler is invoked very frequently
(milliseconds) (must be fast)
Long-term scheduler is invoked very infrequently (seconds,
minutes) (may be slow)
The long-term scheduler controls the degree of
multiprogramming ( the number of processes in memory)
Processes can be described as either:
I/O-bound process spends more time doing I/O than
computations, many short CPU bursts
CPU-bound process spends more time doing
computations; few very long CPU bursts
2.24
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Context Switch
When CPU switches to another process, the system must
save the state of the old process and load the saved state
for the new process
Context-switch time is overhead; the system does no useful
work while switching
Time dependent on hardware support
2.25
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Creation
Parent process creating process
Child process the new process created by the parent process

Parent process create children processes, which, in turn create
other processes, forming a tree of processes
Resource sharing
Parent and children share all resources
Children share subset of parents resources
Parent and child share no resources
Execution
Parent and children execute concurrently
Parent waits until children terminate

2.26
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Creation (Cont.)
Address space
Child duplicate of parent
Child has a program loaded into it
UNIX examples
fork system call creates new process
exec system call used after a fork to replace the
process memory space with a new program
* When a process is created, the OS creates a PCB for the
said process and append this to the list of existing PCBs in
the system. Then, the code for the process is located
(usually residing in the secondary store). If at least one of
these steps is unsuccessful, i.e. no space for PCB is
available or the code can not be found, then the process is
not created (undoing whatever has been done).

2.27
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
A tree of processes on a typical Solaris
2.28
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Termination
5 types of termination:
1. Normal termination - due to a call by the process to a termination
statement.
- uses exit system call.
2. Abnormal termination - is the forced termination of the process by
the OS due to some unrecoverable error like bound violation,
arithmetic error, invalid instructions, I/O failure, data misuse, and
other fault conditions.
3. Cascading termination - a phenomenon of terminating children
processes because the parent process is finished.
4. A parent process has already finished execution and children
processes are no longer needed.
- uses abort system call.
5. Process may be killed due to operating system or user starvation.

2.29
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Process Termination

To handle process termination, the OS deletes the PCB of
the process to free the space and if the process is occupying
memory space such is declared free.

A parent may terminate the execution of one of its children
for a variety of reasons, such as:

The child has exceeded its usage of some of the resources it
has been allocated.
The task assigned to the child is no longer required.

2.30
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Cooperating Processes
Independent process cannot affect or be affected by the execution
of another process
Cooperating process can affect or be affected by the execution of
another process
Any process that shares data with other processes.
Affect or can be affected by other running processes.
may either directly share a logical address space (that is, both
code and data), or be allowed to share data only through files.
requires a means of communicating with one another.
Advantages of process cooperation
Information sharing
Computation speed-up
Modularity
Convenience
2.31
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Interprocess Communication (IPC)
Mechanism for processes to communicate and to
synchronize their actions (useful in distributed environment,
e.g. chat)
Message passing system processes communicate with
each other without resorting to shared variables
IPC facility provides two operations:
send(message) message size fixed or variable
receive(message)
If P and Q wish to communicate, they need to:
establish a communication link between them
exchange messages via send/receive
Implementation of communication link
physical (e.g., shared memory, hardware bus)
logical (e.g., logical properties)
2.32
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Types of Message Passing Systems
2.33
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Direct Communication
Processes must name each other explicitly:
send (P, message) send a message to process P
receive(Q, message) receive a message from process
Q
Properties of communication link
Links are established automatically
A link is associated with exactly one pair of
communicating processes
Between each pair there exists exactly one link
The link may be unidirectional, but is usually bi-
directional
2.34
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Indirect Communication
Messages are directed and received from mailboxes (also
referred to as ports)
Each mailbox has a unique id
Processes can communicate only if they share a
mailbox
Properties of communication link
Link established only if processes share a common
mailbox
A link may be associated with many processes
Each pair of processes may share several
communication links
Link may be unidirectional or bi-directional
2.35
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Synchronization
Message passing may be either blocking or non-blocking
Blocking is considered synchronous
Blocking send : The sending process is blocked until
the message is received
Blocking receive : The receiver blocks until a message
is available
Non-blocking is considered asynchronous
Non-blocking send: The sending process sends the
message and resumes operation
Non-blocking receive: The receiver retrieves either a
valid message or null
2.36
Silberschatz, Galvin and Gagne 2005
Operating System Concepts
Buffering
another issue is whether to store messages in the link if the
process on the other side is not ready to receive it. If the
message is stored, the sender can continue execution
immediately after sending the message.
3 Methods:
1. Zero-capacity does not allow buffering so the other
process must wait until other process is ready to
receive the message. Has a queue with length 0
2. Bounded capacity has a queue with length n and can
store messages until it is full.
3. Unbounded capacity has an infinite queue and the
sender is never delayed.

Das könnte Ihnen auch gefallen