The Great Symbian

Anything under the sun goes here!

Showing posts with label OS4. Show all posts
Showing posts with label OS4. Show all posts

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


DIRECT COMMUNICATION

• Processes must name each other explicitly:
– Symmetric Addressing
• Send (P, message) – send to process P
• Receive(Q, message) – receive from Q
Asymmetric Addressing
•send (P, message) – send to process P
•receive(id, message) – rx from any; system sets id = sender
•Primitives:

–send(A, message) – send a message to mailbox A
–receive(A, message) – receive a message from mailbox A

•Properties of Communication Link
–Links established automatically between pairs
–processes must know each others ID
–Exactly one link per pair of communicating processes

•Disadvantage: a process must know the name or ID of the process(es) it wishes to communicate with


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 communicationlinks.
- 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 to mailbox Areceive(A, message)
receive a message from mailbox A

• Mailbox sharingF P1, P2, and P3 share mailbox A.
- P1, sends; P2 and P3 receive.
- Who gets the message?

• Solutions
- Allow a link to be associated with at most two processes.
- Allow only one process at a time to execute a receiveoperation.
-Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was.


SYNCHRONIZATION

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

Blocking Send: sender blocked until message received by mailbox or process
Nonblocking Send: sender resumes operation immediately after sending
Blocking Receive: receiver blocks until a message is available
Nonblocking Receive: receiver returns immediately with either a valid or null message.

• Blocking is considered synchronous

• Non-blocking is considered asynchronous

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

BUFFERING


• All messaging system require framework to temporarily buffer messages. These queues are implemented in one of three ways:

1.)Zero Capacity – 0 messages
Sender must wait for receiver (rendezvous).

2.) Bounded Capacity – finite length of n messages
Sender must wait if link full.

3.) Unbounded Capacity – infinite lengthSender never waits.

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










•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

OS should be able to create and delete processes dynamically.
A. PROCESS CREATION
  • When the OS or a user process decides to create a new process, it can proceed as follows:
    - Assign a new process identifier and add its entry to the primary process table.
    - Allocate space for the process (program+data) and user stack. The amount of space required can set to default values depending on the process type. If a user process spawns a new process, the parent process can pass these values to the OS.
    - Create process control block.
    - Set appropriate linkage to a queue (ready) is set.
    - Create other necessary data structures (e.g. to store accounting information).
  • Parent process creates children processes, which, in turn create other processes, forming a tree of processes.
  • Resource sharing possibilities
    - Parent and children share all resources.
    - Children share subset of parent’s resources.
    - Parent and child share no resources.
  • Execution possibilities
    - Parent and children execute concurrently.
    - Parent waits until children terminate.
  • Address space possibilities
    - Child duplicate of parent.
    - Child has a program loaded into it.

B. PROCESS TERMINATION

  • A process terminates when it executes last statement and asks the operating system to delete it by using exit system call. At that time, the child process
    - Output data from child to parent (via wait).
    - Process’ resources are deallocated by operating system.
  • Parent may terminate execution of children processes via appropriate system called (e.g. abort). A parent may terminate the execution of one of its children for the following reasons:
    - 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.

A. PROCESS SCHEDULING QUEUES



Job Queue – When a process enters a system, it is put in a job queue.

  • Ready Queue – set of all processes residing in main memory, ready and waiting to execute are kept in ready queue.
  • Device Queues – There may be many processes in the system requesting for an I/O. Since only one I/O request can be entertained for a particular device, a process needing an I/O may have to wait. The list of processes waiting for an I/O device is kept in a device queue for that particular device.

An example of a ready queue and various device queues is shown below.


B. SCHEDULERS

  • A process may migrate between the various queues.
  • The OS must select, for scheduling purposes, processes from these queues.
  • Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue.
    - It is invoked very infrequently (seconds, minutes) Þ (may be slow).
    - It controls the degree of multiprogramming.
  • Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU.
    - Short-term scheduler is invoked very frequently (milliseconds) Þ(must be fast).
  • Midterm scheduler selects which partially executed job, which has been swapped out, should be brought into ready queue.



C. 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 - this is called context switch.

  • The time it takes is dependent on hardware support.

  • Context-switch time is overhead; the system does no useful work while switching.

Steps in Context Switching

  • Save context of processor including program counter and other registers.
  • Update the PCB of the running process with its new state and other associate information.
  • Move PCB to appropriate queue - ready, blocked,
  • Select another process for execution.
  • Update PCB of the selected process.
  • Restore CPU context from that of the selected process.





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

A. PROCESS STATE



A process can be in one of many possible states:

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

  • Terminated: The process has finished execution.


PROCESS TRANSITIONS

As a process executes, it changes its state


Fig. Process State Transition Diagram

B. PROCESS CONTROL BLOCK

  • Each process in the operating system is represented by a process control block (PCB) – also called a task control block.

  • Information associated with each process includes:
    - Process state – new, ready, running, waiting...
    - Process identification information
    ° Unique process identifier (PID) - indexes (directly or indirectly) into the process table.
    ° User identifier (UID) - the user who is responsible for the job.
    ° Identifier of the process that created this process (PPID).
    - Program counter – To indicate the next instruction to be executed for this process.
    - CPU registers – include index registers, general purpose registers etc. so that the process can be restarted correctly after an interrupt occurs.
    - CPU scheduling information – Such as process priority, pointers to scheduling queues etc.
    - Memory-management information – Include base and limit register, page tables etc.
    - Accounting information – Amount of CPU and real time used, time limits, account number, job or process numbers and so on.
    - I/O status information – List of I/O devices allocated to this process, a list of open files etc.





C. THREADS


  • A thread, also called a lightweight process (LWP), is the basic unit of CPU utilization.

  • It has its own program counter, a register set, and stack space.

  • It shares with the pear threads its code section, data section, and OS resources such as open files and signals, collectively called a task.

  • The idea of a thread is that a process has five fundamental parts: code ("text"), data, stack, file I/O, and signal tables. "Heavy-weight processes" (HWPs) have a significant amount of overhead when switching: all the tables have to be flushed from the processor for each task switch. Also, the only way to achieve shared information between HWPs is through pipes and "shared memory". If a HWP spawns a child HWP using fork(), the only part that is shared is the text.
  • Threads reduce overhead by sharing fundamental parts. By sharing these parts, switching happens much more frequently and efficiently. Also, sharing information is not so "difficult" anymore: everything can be shared.

User-Level and Kernel-Level Threads

  • There are tow types of thread: user-level and kernel-level.
  • User-level avoids the kernel and manages the tables itself.
  • These threads are implemented in user-level libraries rather than via system calls.
  • Often this is called "cooperative multitasking" where the task defines a set of routines that get "switched to" by manipulating the stack pointer.
  • Typically each thread "gives-up" the CPU by calling an explicit switch, sending a signal or doing an operation that involves the switcher. Also, a timer signal can force switches.
  • User threads typically can switch faster than kernel threads.

Thread States

  • Threads can be in one of the several states: ready, blocked, running, or terminated.
  • Like process, threads share the CPU and only one thread at a time is in running state.




























FEEDS

Add to Google Reader or Homepage

Click2Sell

Buy

How To Learn Photoshop in Just 2 Hrs

Chatbox

Click Here

About this blog