Thursday, July 30, 2009

INTERPROCESS COMMUNICATION


Direct Communication

Direct communication can be defined as speech that specifically states and directs an action. Most of us grew up hearing direct speech from our parents or teachers: "Get that homework done before you go out to play," or, from our boss today we might hear: "I need this on my desk by Friday."

When to Use Direct Communication:
Direct communication is often necessary in working environments. There are plenty of situations when a direct style is the only appropriate option. The following situations call for this form of speech.


Indirect Communication

Unlike direct communication, a indirect style of speech is not typically authoritative, rather it encourages input from the listener. By using this method, you give the other person the opportunity to speak up. An indirect style, makes them feel as if their ideas are important. This style of communication places the listener in the "one-up" position.

When to Use Indirect Communication:
Like direct communication, indirect communication can be very useful in the workplace. This method can make teams run more smoothly and create an environment of friendly respect.


Synchronization

refers to one of two distinct but related concepts: synchronization of processes, and synchronization of data. Process synchronization refers to the idea that multiple processes are to join up or handshake at a certain point, so as to reach an agreement or commit to a certain sequence of action. Data synchronization refers to the idea of keeping multiple copies of a dataset in coherence with one another, or to maintain data integrity. Process synchronization primitives are commonly used to implement data synchronization.

=>processes takes place by calls to send and receive primitives

  • Blocking send

A blocking send returns as soon as the send buffer is free for reuse, that is, as soon as the last byte of data has been sent or placed in an internal buffer.

  • Nonblocking send

A non-blocking send returns as soon as possible, that is, as soon as it has posted the send. The buffer might not be free for reuse.

  • Blocking receive

A blocking receive returns as soon as the data is ready in the receive buffer.

  • Nonblocking receive

A non-blocking receive returns as soon as possible, that is, either with a flag that the data has not arrived yet or with the data in the receive buffer.


Buffering

=>Buffering Messages reside in a temporary queue Zero capacity Bounded capacity Unbounded capacity.

Link may have some capacity that determines the number of message that can be temporarily queued in it .

  • Zero Capacity

Explicit buffering – Zero-capacity (blocking sender, receiver)

Zero capacity: (queue of length 0)

  1. No messages wait.
  2. Sender must wait until receiver receives the message — this synchronization to exchange data is called a rendezvous.
  • Bounded Capacity

– Bounded capacity: when queue is not full, message is copied into buffer (or a pointer is kept).

Bounded capacity: (queue of length)

  1. If receiver’s queue is not full, new message is put on queue,and sender can continue executing immediately.
  2. If queue is full, sender must block until space is available in the queue.
  • Unbounded Capacity

Unbounded capacity: (infinite queue)

  1. Sender can always continue


Producer-Consumer Example

  • Procedure

A producer which generates data items and puts them in a buffer e.g. from a file

  • Consumer

A consumer which removes items from the buffer e.g. to a printer.

Thursday, July 16, 2009

Interprocess Communication
  • For communication and synchronization
    –Shared memory
    –OS provided IPC
  • Message system
    –no need for shared variable
    – 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)
Cooperating Process

  • Advantages of process cooperation
    –Information sharing
    –Computation speed-up
    –Modularity
    –Convenience
  • Independent process cannot affect/be affected by the execution of another process, cooperating ones can
  • Issues
    –Communication
    –Avoid processes getting into each other’s way
    –Ensure proper sequencing when there are dependencies
  • Common paradigm: producer-consumer
    –unbounded-buffer - no practical limit on the size of the buffer
    –bounded-buffer - assumes fixed buffer size
The Concept of Process

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

Primary Process States

The following typical process states are possible on computer systems of all kinds. In most of these states, processes are "stored" on main memory.






b. Process Control Block

A Process Control Block (PCB, also called Task Control Block or Task Struct) is a data structure in the operating system kernel containing the information needed to manage a particular process. The PCB is "the manifestation of a process in an operating system".

Included information:


Implementations differ, but in general a PCB will include, directly or indirectly:

  • The identifier of the process (a process identifier, or PID)
  • Register values for the process including, notably,
    the
    Program Counter value for the process
  • The address space for the process
  • Priority (in which higher priority process gets first preference. eg., nice value on Unix operating systems)
  • Process accounting information, such as when the process was last run, how much CPU time it has accumulated, etc.
  • Pointer to the next PCB i.e. pointer to the PCB of the next process to run

  • I/O Information (i.e. I/O devices allocated to this process, list of opened files, etc)


During a context switch, the running process is stopped and another process is given a chance to run. The kernel must stop the execution of the running process, copy out the values in hardware registers to its PCB, and update the hardware registers with the values from the PCB of the new process.

c. Threads

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.


Processing Scheduling

a. 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.
  • Process migration between the various queues.

b.Schedulers

Scheduler is a tool that is intented to help understand how real-time algorithms work.

As of release 10.0, HP-UX implements four schedulers, two time-share and two real-time.
To choose a scheduler, you can use the user command, rtsched(1), which executes processes with your choice of scheduler and enables you to change the real-time priority of currently executing process ID.

rtsched -s scheduler -p priority command [arguments] rtsched [ -s scheduler ] -p priority -P pid

Likewise, the system call rtsched(2) provides programmatic access to POSIX real-time scheduling operations.

c. Context Switch

A context switch is the computing process of storing and restoring the state (context) of a CPU such that multiple processes can share a single CPU resource. The context switch is an essential feature of a multitasking operating system. Context switches are usually computationally intensive and much of the design of operating systems is to optimize the use of context switches. A context switch can mean a register context switch, a task context switch, a thread context switch, or a process context switch. What constitutes the context is determined by the processor and the operating system.



Operation on Process

a. Process Creation

Process 0 is created and initialized at system boot time but all other processes are created by a fork() or vfork() system call.


  • The fork() system call causes the creation of a new process. The new (child) process is an exact copy of the calling (parent) process.
  • vfork() differs from fork() only in that the child process can share code and data with the calling process (parent process). This speeds cloning activity significantly at a risk to the integrity of the parent process if vfork() is misused.
b. Process Termination

Processes terminate in one of two ways:

  • Normal Termination occurs by a return from main or when requested by an explicit call to exit or _exit.
  • Abnormal Termination occurs as the default action of a signal or when requested by abort.


When a process finishes executing, HP-UX terminates it using the exit system call.
Circumstances might require a process to synchronize its execution with a child process. This is done with the wait system call, which has several related routines.
During the exit system call, a process enters the zombie state and must dispose of child processes. Releasing process and thread structures no longer needed by the exiting process or thread is handled by three routines
-- freeproc(), freethread(), and kissofdeath().

Thursday, July 9, 2009

Quiz #3

1.What are the major activities of the OS with regards to process management?

=>Process creation and deletion

=>Process suspenion and resumption

=>Provision of mechanisms for:

  • * process synchronization
  • *process communication
  • *deadlock handling

2.What are the major activities of the OS with regards to main-memory management?

=>Keep track which parts of memory are currently being used and by whom.

=>Decide which processes to load when memory space becomes available.

=>Allocate and deallocate memory space as needed.

3.What are the major activities of the OS with regards to secondary-storage management?

=>Free space management

=>Storage allocation

=>Disk scheduling

4.What are the major activities of the OS with regards to file management?

=>File creation and deletion

=>Directory creation and deletion

=>Support of primitives for manipulating files and directories

=>File backup on stable (nonvolatile) storage media

=>Mapping files onto secondary storage

5.What is the purposeof the command interpreter?

=> It reads commands from the user or from a file of commandsand executes them, usually by turning them into one or more systemcalls. It is usually not part of the kernel since the command interpreteris subject to changes.