Chapter 2 - OS Services
Transcript of Chapter 2 - OS Services
-
8/11/2019 Chapter 2 - OS Services
1/36
Operating-System Services
-
8/11/2019 Chapter 2 - OS Services
2/36
2.2 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Operating System Services
One set of operating-system services provides functions that arehelpful 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 intomemory and to run that program, end execution, either normally orabnormally (indicating error)
I/O operations - A running program may require I/O, which may involvea 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, createand delete them, search them, list file Information, permissionmanagement.
-
8/11/2019 Chapter 2 - OS Services
3/36
2.3 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Operating System Services (Cont.)
One set of operating-system services provides functions that arehelpful to the user (Cont):
CommunicationsProcesses may exchange information, on the samecomputer or between computers over a network
Communications may be via shared memory or through messagepassing (packets moved by the OS)
Error detectionOS needs to be constantly aware of possible errors
May occur in the CPU and memory hardware, in I/O devices, in userprogram
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
-
8/11/2019 Chapter 2 - OS Services
4/36
2.4 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Operating System Services (Cont.)
Another set of OS functions exists for ensuring the efficient operation of thesystem itself via resource sharing
Resource allocation - When multiple users or multiple jobs runningconcurrently, 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/Odevices) may have general request and release code.
Accounting -To keep track of which users use how much and what kindsof computer resources
Protection and security - The owners of information stored in a multiuseror networked computer system may want to control use of that information,concurrent processes should not interfere with each other
Protectioninvolves ensuring that all access to system resources is
controlled Securityof 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 beinstituted throughout it.
-
8/11/2019 Chapter 2 - OS Services
5/36
2.5 Silberschatz, Galvin and Gagne 2005Operating System Concepts
User Operating System Interface - CLI
CLI allows direct command entry Sometimes implemented in kernel, sometimes by systems
program
Sometimes multiple flavors implementedshells
Primarily fetches a command from user and executes it
Sometimes commands built-in, sometimes just names ofprograms
If the latter, adding new features doesnt require shell
modification
-
8/11/2019 Chapter 2 - OS Services
6/36
2.6 Silberschatz, Galvin and Gagne 2005Operating System Concepts
User Operating System Interface - GUI
User-friendly desktopmetaphor interface
Usually mouse, keyboard, and monitor
Iconsrepresent files, programs, actions, etc
Various mouse buttons over objects in the interface causevarious 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)
-
8/11/2019 Chapter 2 - OS Services
7/36
Processes
-
8/11/2019 Chapter 2 - OS Services
8/362.8 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Process Concept
Processa program in execution; process execution mustprogress in sequential fashion
are active entities which executed in sequentialfashion.
A program residing on your disk will only be named aprocess when it already demands execution.
is more than the program code. It also includes thecurrent state, activity and other relevant information.
*Operating system processes execute system code and userprocesses execute user code.
-
8/11/2019 Chapter 2 - OS Services
9/362.9 Silberschatz, Galvin and Gagne 2005Operating 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 tooccur
ready: The process is waiting to be assigned to aprocessor
terminated: The process has finished execution
-
8/11/2019 Chapter 2 - OS Services
10/362.10 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Diagram of Process State
-
8/11/2019 Chapter 2 - OS Services
11/362.11 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Process State
Transitions:
dispatch transition from READY to RUNNING. This is theassignment of the CPU to the process.
block (I/O or event wait)transition from RUNNING toWAITING. This happens when a process voluntarily
relinquishes control of the CPU due to some event. wakeup (I/O or event complet ion) transition from
WAITING to READY. This happens when the event beingwaited 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 CPUbecause a higher priority job is ready to take control of theCPU or in time-sharing systems the process consumes itstime share.
-
8/11/2019 Chapter 2 - OS Services
12/36
-
8/11/2019 Chapter 2 - OS Services
13/362.13 Silberschatz, Galvin and Gagne 2005Operating 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 forthis purpose.
CPU Register
the values of the registers must be saved when an interruptoccurs to ensure that the process can progress afterwards.
CPU scheduling information
This information contains various scheduling parameters anddetails. 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 theprocess.
-
8/11/2019 Chapter 2 - OS Services
14/362.14 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Process Control Block (PCB)
PCB- simply acts as a repository for any informationthat may vary form process to process.
2 characteristics of process:
1. execution process state, program counter,
scheduling
2. ownership memory management, andresource management.
-
8/11/2019 Chapter 2 - OS Services
15/362.15 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Process Control Block (PCB)
-
8/11/2019 Chapter 2 - OS Services
16/362.16 Silberschatz, Galvin and Gagne 2005Operating System Concepts
CPU Switch From Process to Process
-
8/11/2019 Chapter 2 - OS Services
17/362.17 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Threads
A process is a program that performs a single THREADof execution.
a basic unit of CPU utilization( basic unit of execution).lightweight process
consists of program counter, a register set and a stackspace.
operate like processes in many aspects. ( has severalstates, executes in sequential fashion, can use CPU at a
time)are not independent of one another.designed to aid one another.
-
8/11/2019 Chapter 2 - OS Services
18/362.18 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Threads
Multithreadingthe ability of an operating system to support multiple threadsof 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 avoidedsince there is an extensive sharing of resources among peerthreads.2. It takes a far less time to create a new thread in an existingprocess 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 differentexecuting programs.
-
8/11/2019 Chapter 2 - OS Services
19/362.19 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Process Scheduling
Question: How do we run processes concurrently if we
only have one CPU?
Answer: Process Scheduling (by having an order ofexecution )
Scheduling Queues:
Job queueset of all processes in the system Ready queueset of all processes residing in main
memory, ready and waiting to execute
Device queuesset of processes waiting for an I/Odevice. Each device has its own device queue.
Processes migrate among the various queues
-
8/11/2019 Chapter 2 - OS Services
20/362.20 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Ready Queue And Various I/O Device Queues
-
8/11/2019 Chapter 2 - OS Services
21/362.21 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Representation of Process Scheduling
Queueing Diagram
Rectangular box- queueCircle-resourcesArrows- flow of processes
-
8/11/2019 Chapter 2 - OS Services
22/362.22 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Schedulers
A process migrates between the various schedulingqueues 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 allocatesCPU
-
8/11/2019 Chapter 2 - OS Services
23/36
2.23 Silberschatz, Galvin and Gagne 2005Operating 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
mu l t iprogramm ing ( the number of processes in memo ry)
Processes can be described as either:
I/O-bound processspends more time doing I/O thancomputations, many short CPU bursts
CPU-bound process
spends more time doingcomputations; few very long CPU bursts
-
8/11/2019 Chapter 2 - OS Services
24/36
2.24 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Context Switch
When CPU switches to another process, the system mustsave the state of the old process and load the saved statefor the new process
Context-switch time is overhead; the system does no usefulwork while switching
Time dependent on hardware support
-
8/11/2019 Chapter 2 - OS Services
25/36
2.25 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Process Creation
Parent processcreating process
Child processthe new process created by the parent process
Parent process create children processes, which, in turn createother 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
-
8/11/2019 Chapter 2 - OS Services
26/36
2.26 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Process Creation (Cont.)
Address space
Child duplicate of parent
Child has a program loaded into it
UNIX examples
forksystem call creates new process execsystem call used after a forkto replace the
process memory space with a new program
* When a process is created, the OS creates a PCB for thesaid 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 ofthese steps is unsuccessful, i.e. no space for PCB isavailable or the code can not be found, then the process isnot created (undoing whatever has been done).
-
8/11/2019 Chapter 2 - OS Services
27/36
2.27 Silberschatz, Galvin and Gagne 2005Operating System Concepts
A tree of processes on a typical Solaris
-
8/11/2019 Chapter 2 - OS Services
28/36
2.28 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Process Termination
5 types of term inat ion:
1. Normal termination - due to a call by the process to a terminationstatement.
- uses exit system call.
2. Abnormal termination - is the forced termination of the process bythe OS due to some unrecoverable error like bound violation,arithmetic error, invalid instructions, I/O failure, data misuse, andother fault conditions.
3. Cascading termination - a phenomenon of terminating childrenprocesses because the parent process is finished.
4. A parent process has already finished execution and childrenprocesses are no longer needed.
- uses abort system call.
5. Process may be killed due to operating system or user starvation.
-
8/11/2019 Chapter 2 - OS Services
29/36
2.29 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Process Termination
To handle process termination, the OS deletes the PCB ofthe process to free the space and if the process is occupyingmemory space such is declared free.
A parent may terminate the execution of one of its childrenfor 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.
-
8/11/2019 Chapter 2 - OS Services
30/36
-
8/11/2019 Chapter 2 - OS Services
31/36
2.31 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Interprocess Communication (IPC)
Mechanism for processes to communicate and to
synchronize their actions (useful in distributed environment,e.g. chat)
Message passing systemprocesses communicate witheach other without resorting to shared variables
IPC facility provides two operations:
send(message)message size fixed or variable
receive(message)
If Pand Qwish to communicate, they need to:
establish a communicationlinkbetween them
exchange messages via send/receive
Implementation of communication link
physical (e.g., shared memory, hardware bus)
logical (e.g., logical properties)
-
8/11/2019 Chapter 2 - OS Services
32/36
2.32 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Types of Message Passing Systems
-
8/11/2019 Chapter 2 - OS Services
33/36
2.33 Silberschatz, Galvin and Gagne 2005Operating 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 processQ
Properties of communication link
Links are established automatically
A link is associated with exactly one pair ofcommunicating processes
Between each pair there exists exactly one link
The link may be unidirectional, but is usually bi-directional
-
8/11/2019 Chapter 2 - OS Services
34/36
-
8/11/2019 Chapter 2 - OS Services
35/36
2.35 Silberschatz, Galvin and Gagne 2005Operating System Concepts
Synchronization
Message passing may be either blocking or non-blocking
Blockingis considered synchronous
Blocking send : The sending process is blocked untilthe message is received
Blocking receive : The receiver blocks until a message
is available
Non-blockingis considered asynchronous
Non-blocking send: The sending process sends themessage and resumes operation
Non-blocking receive: The receiver retrieves either avalid message or null
-
8/11/2019 Chapter 2 - OS Services
36/36
Buffering
another issue is whether to store messages in the link if theprocess on the other side is not ready to receive it. If themessage is stored, the sender can continue executionimmediately after sending the message.
3 Methods:
1. Zero-capacity does not allow buffering so the otherprocess must wait until other process is ready toreceive the message. Has a queue with length 0
2. Bounded capacityhas a queue with length n and canstore messages until it is full.
3. Unbounded capacity has an infinite queue and thesender is never delayed.