B L O G G E R

--> This is JAN AUSTIN EVANGELISTA hir signing..

Showing posts with label OS 4. Show all posts
Showing posts with label OS 4. Show all posts

Interprocess Communication


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.
– The link may be unidirectional (e.g. signaling), but is
usually bi-directional (e.g. sockets).

----------

INDIRECT COMMUNICATION
Messages are directed and received from
mailboxes (also referred to as ports).
– Each mailbox has a unique id. (e.g. shared memory,
shared file, message Q)
– Processes can communicate only if they share a
mailbox.
Properties of communication link
– A link may be associated with many processes.
– Each pair of processes may share several
communication links.
– Link may be unidirectional or bi-directional.
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 A
receive(A, message) – receive a message
from mailbox A

----------

SYNCHRONIZATION
Blocking send
- suspend sending process until message received
Nonblocking send
- resume process immediately after sending message
Blocking receive
- suspend receiving process until data is received
Nonblocking receive
- return either a message or
- null if no message is immediately available

Synchronization Trade-Offs
Blocking
- guarantees message has been delivered
- drastically reduces performance
Non-Blocking
- much better performance (hides latency of message sending)
- could cause errors if messages are lost

----------

BUFFERING
• Buffering allows messages to be saved and read or transmitted later
• Requires sufficient memory to store messages
• Can drastically improve performance of applications

Types of Buffering
Zero Capacity
- no buffering at all
- must be "listening" when a message comes in
Bounded Capacity
- some max, n, of messages will be buffered
- be careful when queue gets full
Unbounded Capacity
- no limit to the number of message
- not usually very realistic assumption
- this is not very realistic, buffers usually have finite capacity

Buffering Example



----------

Producer-Consumer Example
• One process generates data – the producer

• The other process uses it – the consumer

• If directly connected – time coordination

- How would they coordinate the time ??



• One process generates data – the producer

• The other process uses it – the consumer

• If not directly connected – have a buffer

- Buffer must be accessible to both

- Finite Capacity N – Number in use - K





5) Inter-Process Communication (IPC)


~ Mechanism for processes to communicate and to synchronize their actions

~ Message 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)

4) Cooperating Process


~ 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

~ Advantages of process cooperation
>>Information sharing
>>Computation speed-up
>>Modularity
>>Convenience

3) Operations on Process (Process Operations)


PROCESS CREATION

~ 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 parent’s resources
>>Parent and child share no resources

~ Execution
>>Parent and children execute concurrently
>>Parent waits until children terminate



~ 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


PROCESS TERMINATION

~ Process executes last statement and asks the OS to delete it (exit)
>>Output data from child to parent (via wait)
>>Process’ resources are deallocated by OS

~ Parent may terminate execution of children processes (abort)
>>Child has exceeded allocated resources
>>Task assigned to child is no longer required
>>If parent is exiting
-->Some OS do not allow child to continue if its parent terminates
--All children terminated - cascading termination

2) Process Scheduling


Representation of Process Scheduling



-----------------

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




SCHEDULERS

~ 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

Addition of Medium Term Scheduling



~ 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

~ 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


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

1) The Concept of Process (OS)


An operating system executes a variety of programs:
~ Batch system – jobs
~ Time-shared systems – user programs or tasks

Textbook uses the terms job and process almost
interchangeably.

Process – a program in execution; process execution
must progress in sequential fashion.

A process includes:
~ program counter
~ stack
~ data section

-----------------

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.

Diagram of Process State




PROCESS CONTROL BLOCK(PCB)

Information associated with each process
~ Process state
~ Program counter
~ CPU registers
~ CPU scheduling information
~ Memory-management information
~ Accounting information
~ I/O status information

Process Control Block (PCB)




THREADS



In computer science, a thread of execution results from a fork of a computer program into two or more concurrently running tasks. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources.

On a single processor, multithreading generally occurs by time-division multiplexing (as in multitasking): the processor switches between different threads. This context switching generally happens frequently enough that the user perceives the threads or tasks as running at the same time. On a multiprocessor or multi-core system, the threads or tasks will generally run at the same time, with each processor or core running a particular thread or task. Support for threads in programming languages varies: a number of languages simply do not support having more than one execution context inside the same program executing at the same time. Examples of such languages include Python, and OCaml, because the parallel support of their runtime support is limited by the use of a central lock, called "Global Interpreter Lock" in Python, "master lock" in Ocaml. Other languages may be limited because they use threads that are user threads, which are not visible to the kernel, and thus cannot be scheduled to run concurrently. On the other hand, kernel threads, which are visible to the kernel, can run concurrently.

Many modern operating systems directly support both time-sliced and multiprocessor threading with a process scheduler. The kernel of an operating system allows programmers to manipulate threads via the system call interface. Some implementations are called a kernel thread, whereas a lightweight process (LWP) is a specific type of kernel thread that shares the same state and information.

Programs can have user-space threads when threading with timers, signals, or other methods to interrupt their own execution, performing a sort of ad-hoc time-slicing.

Threads compared with processes
Threads differ from traditional multitasking operating system processes in that:

~ processes are typically independent, while threads exist as subsets of a process
~ processes carry considerable state information, where multiple threads within a process share state as well as memory and other resources
~ processes have separate address spaces, where threads share their address space
~ processes interact only through system-provided inter-process communication mechanisms.
~ Context switching between threads in the same process is typically faster than context switching between processes.

Systems like Windows NT and OS/2 are said to have "cheap" threads and "expensive" processes; in other operating systems there is not so great a difference except the cost of address space switch which implies a TLB flush.

Welcome

=] an eXciting WORLD awaits you [=

"dount count your
friends
on a
SUNNY DAY
when the sky is blue
and
laughter is
abundant.
Instead,
wait for the
STORM
when the clouds are dark
and
smiles are
scarce.
When someone
stands
besides
you
and
lift your
SPIRITs high,
then you'll
know who deserves
to be
called
FRIENDS..
"

Followers

Labels