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

Thursday, July 30, 2009

Producer

*Producer :
»get a message block from mayproduce

»put data item in block

»send message to mayconsume

*consumer :

»get a message from mayconsume

»consume data in block

»return empty message block to mayproduce mailbox

Buffering

•Buffering - the number of messages that can reside in a link temporarily

–Zero capacity - queue length 0

»sender must wait until receiver ready to take the message

–Bounded capacity - finite length queue
»messages can be queued as long as queue not full

»otherwise sender will have to wait

–Unbounded capacity

»any number of messages can be queued - in virtual space?

»sender never delayed

Interprocess Communication

  • Direct Communication


–each process wanting to communicate must explicitly name the recipient or sender of the communication

–send and receive primitives defined:
send ( P, message ) : send a message to process P
receive ( Q, message ) : receive a message from process Q


–a link established automatically between every pair of processes that want to communicate
»processes only need to know each other’s identity

–link is associated with exactly two processes

–link is usually bidirectional but can be unidirectional

– Process A Process Bwhile (TRUE) { while (TRUE) { produce an item receive ( A, item ) send ( B, item ) consume item} }

  • Indirect Communication


•messages sent to and received from mailboxes (or ports)

–mailboxes can be viewed as objects into which messages placed by processes and from which messages can be removed by other processes

–each mailbox has a unique ID

–two processes can communicate only if they have a shared mailbox


send ( A, message ) : send a message to mailbox Areceive ( A, message ) :

receive a message from mailbox A

  • Synchronization

- Message passing may be either blocking or non-blocking.

• Blocking is considered synchronous

• Non-blocking is considered asynchronous

- Send and receive primitives may be either blocking or non-blocking.

Thursday, July 16, 2009

Inter-process communication

Inter-process communication (IPC) is a set of techniques for the exchange of data among multiple threads in one or more processes. Processes may be running on one or more computers connected by a network. IPC techniques are divided into methods for message passing, synchronization, shared memory, and remote procedure calls (RPC).

The method of IPC used may vary based on the bandwidth and latency of communication between the threads, and the type of data being communicated.

There are several reasons for providing an environment that allows process cooperation:
Information sharing Computation speedup Modularity Convenience IPC may also be referred to as inter-thread communication and inter-application communication.
IPC, on par with the address space concept, is the foundation for address space independence/isolation.[1]

Cooperating processes

Once we have multiple processes or threads, it islikely that two or more of them will want tocommunicate with each other

• Process cooperation (i.e., interprocesscommunication) deals with three main issues

– Passing information between processes/threads

– Making sure that processes/threads do not interfere witheach other

– Ensuring proper sequencing of dependent operations

• These issues apply to both processes and theads– Initially we concentrate on shared memory mechanismswe have multilple

Operating in Process

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

>Process executes last statement and asks the operating system to delete 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.

>Cascading termination.

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

>Device queues – set of processes waiting for an I/O device.

>Processes migrate between the various queues.

  • Schedules

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

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

Process

  • Process State

In a multitasking computer system, processes may occupy a variety of states. These distinct states may not actually be recognized as such by the operating system kernel, however they are a useful abstraction for the understanding of processes.

  • Process Control Block

-Information associated with each process.

>Process ID

>Process state

>Program countern CPU registers

>CPU scheduling information

>Memory-management information

>Accounting information

>I/O status information

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