Upload
nitesh-tarbani
View
214
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Operating System
Citation preview
Unit 1Introduction to Operating System
Operating System
Definition: Operating System
The operating system controls and coordinates the use of the hardware among the various application programs for the various users.
Abstract View of System Components
Operating System Services Program execution – system capability to load a
program into memory and to run it. I/O operations – since user programs cannot execute
I/O operations directly, the operating system must provide some means to perform I/O.
File-system manipulation – program capability to read, write, create, and delete files.
Communications – exchange of information between processes executing either on the same computer or on different systems tied together by a network. Implemented via shared memory or message passing.
Error detection – ensure correct computing by detecting errors in the CPU and memory hardware, in I/O devices, or in user programs.
Additional Operating System Functions
Additional functions exist not for helping the user, but rather for ensuring efficient system operations.• Resource allocation – allocating resources to
multiple users or multiple jobs running at the same time.
• Accounting – keep track of and record which users use how much and what kinds of computer resources for account billing or for accumulating usage statistics.
• Protection – ensuring that all access to system resources is controlled.
Process Concept
Process – a program in execution; process execution must progress in sequential fashion
A process includes: program counter stack data section
Process State Transition Diagram
Process State Transition Diagram
New: The process is being created. Running: Instructions are being
executed. Waiting: The process is waiting for
some event to occur (such as an I/O completion or reception of a signal). Ready: The process is waiting to be
assigned to a processor.
Process Control Block
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
Context Switch
Process Scheduling
The objective of multiprogramming is to have some process running at all times, so as to maximize CPU utilization.
The objective of time-sharing is to switch the CPU among processes so frequently that users can interact with each program while it is running.
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
Processes migrate among the various queues
Ready Queue And Various I/O Device Queues
Queuing Diagram: Representation of Process Scheduling
Operations on Process
Process Creation Process Termination
Process Creation
Parent process creates 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 parent’s resources. Parent and child share no resources.
Execution Parent and children execute concurrently. Parent waits until children terminate.
Process Creation
Address space Child duplicate of parent. Child has a program loaded into it.
In UNIX, fork system call creates new process execlp system call used after a fork to
replace the process’ memory space with a new program.
Fork System Call
System call fork() is used to create processes. It takes no arguments and returns a process ID. If fork() returns a negative value, the creation
of a child process was unsuccessful. fork() returns a zero to the newly created child
process. fork() returns a positive value, the process ID
of the child process, to the parent. a process can use function getpid() to retrieve
the process ID assigned to this process.
Unix Example: Child duplicate of parent
Unix Example : Child has a program loaded into it
Process Termination
Process executes last statement and asks the operating system to decide it (exit). Output data from child to parent (via wait). Process’ resources are deallocated by operating
system. Parent may terminate execution of children
processes (abort). Child has exceeded allocated resources. Task assigned to child is no longer required. Parent is exiting.▪ Operating system does not allow child to continue if its
parent terminates.
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
Needs of process cooperation Information sharing Computation speed-up Modularity Convenience
Producer(P)-Consumer(C)
p C
Producer-Consumer Problem
Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process unbounded-buffer places no practical
limit on the size of the buffer bounded-buffer assumes that there is a
fixed buffer size
Producer-Consumer Problem
Producer process
item nextProduced;
while (1) { while (counter == BUFFER_SIZE)
; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; counter++;}
Consumer process item nextConsumed;
while (1) { while (counter == 0)
; /* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; counter--;}
Interprocess Communication (IPC)
Mechanism for processes to communicate and to synchronize their actions
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
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
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
Indirect Communication
Operations create a new mailbox send and receive messages through mailbox destroy a mailbox
Primitives are defined as:send(A, message) – send a message to mailbox Areceive(A, message) – receive a message from mailbox A
Multithreading
A thread (or lightweight process) is a basic unit of CPU utilization; it consists of: program counter register set stack space
A thread shares with threads of same process: code section data section operating-system resources
Benefits
Responsiveness
Resource Sharing
Economy
Utilization of MP Architectures
Types of Thread
User-Level Thread
Kernel-Level Thread
Multithreading Models
Many-to-One
One-to-One
Many-to-Many
Many to One Model
Many user-level threads mapped to single kernel thread.
One to One Model
Each user-level thread maps to kernel thread.
Many to Many Model
Allows many user level threads to be mapped to many kernel threads.