Lecture 02 Process Management

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Lecture 02 Process Management - Presentation Transcript

    1. Real-Time Operating Systems by Koliya Pulasinghe B.Sc.Eng.(Hons.), Ph.D., MIET, MIEEE
    2. Process Management
    3. Objectives
      • To discuss process concept and the need for process scheduling.
      • To show different operation on processes and how processes cooperate with each other, and inter-process communication.
    4. Process Concept
      • Early computers allowed only one program to be executed at a time. (the program has complete access to all system resources.)
      • Current-day computer systems allow multiple programs to be executed concurrently.
      • These needs resulted in the notion of a process , which is a program in execution
      • All these processes can execute concurrently ,with the CPU is multiplexed among them.
    5. Process Concept
      • In batch systems, we call the program as jobs ; In time-shared systems, we call them user programs or tasks ;
      • Even on a single user system , a user may be able to run several programs at one time: a word processor, web browser, etc.
      • In many respects all these activities are similar, so we call all of them processes.
      • A process is a Program in execution.
      • Process execution must progress in a sequential fashion.
    6. The process
      • A process is more than just the program code.
      • A process includes:
        • Program counter ; containing process’s current activity and it points to the next instruction to execute.
        • Contents of processor registers .
        • Stack ; containing temporary data : subroutine parameters, return addresses, temporary variables.
        • Data section ; containing global variables.
    7. Program vs. Process
      • Is a program process?
        • No, Program is a passive entity , such as the contents of a file stored on disk,
        • whereas a process is an active entity , with a program counter specifying the next instruction to execute and a set of associated resources.
      • Two processes may be associated with the same program; however they are considered two separate execution sequences.
    8. Process State
      • As a process executes, it changes state.
      • Each process may be in one of the following process 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 processor.
        • Terminated – the process has finished execution.
    9. Diagram of Process State
    10. Process Control Block(PCB)
      • Information associated with each process is stored in a PCB (Process Control Block)
      • Each process is represented by its PCB.
      • Each PCB contains:
        • Process number (pid) .
        • Process state : new, ready, running, waiting, etc.
        • Program counter : shows the address of next instruction to be executed.
        • CPU registers : the registers vary in number and type, depending on the computer architecture.
    11. Process Control Block (PCB)
      • Each PCB contains:
        • CPU scheduling information : process priority, pointers to scheduling queues, etc.
        • Memory management information : base and limit register values, page tables, etc.
        • Accounting information : amount of CPU and time used,etc.
        • I/O status information : the list of I/O devices allocated to this process, a list of open files, etc.
    12. Process Control Block (PCB)
    13. CPU Switch From Process to Process
    14. Process Scheduling
      • 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.
      • A uniprocessor system can run only one process and other processes can wait until the CPU is free and can be rescheduled.
    15. Process Scheduling Queues
      • Job queue – All processes entering the system are put in a job queue.
      • 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;each device has its own device queue.
      • Process migrates between the various queues.
    16. Ready Queue And Various I/O Device Queues
    17. Representation of Process Scheduling
    18. Schedulers
      • A process migrates between various scheduling queues.
      • Selection on which process to migrate is done by the appropriate scheduler.
      • Long-term scheduler (or job scheduler )
        • selects which processes should be brought into the ready queue.
        • Is invoked very infrequently (seconds, minutes) . It may be slow; time sharing system often have no long-term scheduler.
        • Controls the degree of multiprogramming.
    19. Schedulers…..
      • Short-term scheduler (or CPU scheduler )
        • selects which process should be executed next and allocated CPU.
        • is invoked very frequently (milliseconds). Therefore it must be fast.
    20. Schedulers (contd.) Long-term short-term
      • 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.
      • Long-term scheduler needs to select a good mix of I/O bound and CPU bound processes .
      Schedulers
    21. Context Switch
      • When CPU switches to another process, the system must save the state of the old process and load the saved state for new process.
      • Context-switch time is overhead; the system does no useful work while switching. This leads to a performance bottleneck.
      • Context-switch-time is dependent on hardware support; typically from 1 to 1000 microseconds.
    22. Context Switch
      • When do we switch CPU?
        • Job voluntarily waits (system calls).
        • Interrupt: Higher priority event/job needs attention.
        • Interrupt: Timer.
    23. Operations on processes
      • Process Creation
      • Process Termination
      • Operating System must provide a mechanism for process creation and deletion
    24. Process Creation
      • Parent process creates children processes, which, in turn create other processes, forming a tree of processes; in Unix use system call fork( ).
      • A process needs resources (CPU time, memory, files, I/O).
      • When a process creates a sub-process:
        • For resources following possibilities exist
          • Parent and children may share all resources.
          • Children may share subset of parent’s resources.
          • Parent and children may share no resources.
        • For execution following possibilities exist
          • Parent and children may execute concurrently.
          • Parent may wait until children terminate.
        • For address space following possibilities exist
          • Child process address space is duplicate of parent’s.
          • Child has a program loaded into it. -> in UNIX: use of execlp().
    25. Process termination
      • A process terminates when it executes last statement and asks the OS to delete it ( exit ); at that point, the process may output data from child to parent (via wait ), and process’ resources are deallocated by the OS.
      • Parent may terminate execution of children processes (abort); Reasons for termination:
        • Child has exceeded allocated resources.
        • Task assigned to child is no longer required.
        • Parent is exiting, and OS does not allow child to continue if its parent terminates.
    26. Cooperating Processes
      • The concurrent processes executing in OS may be either independent or cooperating processes.
        • Independent processes cannot affect or be affected by the execution of another process.
        • Cooperating processes can affect or be affected by the execution of another process.
    27. Advantages of process cooperation:
      • Information sharing
        • several users may need the same piece of information.
      • Computation speed-up
        • break a task into subtasks and execute in parallel
      • Modularity
        • dividing the system function into separate processes.
      • Convenience
        • A user may want to do editing, printing in parallel.
    28. Example of concurrent processes:
      • Producer-consumer problem
        • Paradigm for cooperating processes; producer process produces information that is consumed by a consumer process .
        • To allow producer and consumer processes to run concurrently, there is a buffer of items that can be filled by the producer, and emptied by the consumer.
          • Unbounded-buffer places no practical limit on the size of the buffer.
          • Bounded-buffer assumes that there is a fixed buffer size.
        • The buffer can be in a form of shared memory, or provided by the OS through the use of interprocess-communication (IPC).
    29. Interprocess Communication (IPC)
      • Cooperating processes can communicate:
        • via a shared-memory environment .
        • via an interprocess-communication facility . (means provided by OS for processes to communicate; best provided by a message passing system.)
      • The function of a message system
        • processes communicate with each other without resorting to shared variables.
    30. IPC
      • IPC facility provides at least 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.
    31. IPC
      • Several methods for logically implementing a link and send / receive operations:
        • Direct or indirect communication.
        • Symmetric or asymmetric communication.
        • Automatic or explicit buffering.
        • Send by copy or send by reference.
        • Fixed-sized or variable-sized messages.
    32. Direct communication
      • In direct-communication, each process must explicitly name the recipient or sender of the communication.
      • Primitives used:
        • Send (P, message) – send a message to process P.
        • Receive (Q, message) – receive a message from process Q.
    33. Direct communication …..
      • Properties of communication link for this scheme:
        • 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 bidirectional.
    34. Indirect communication
      • Messages are sent to and received from mailboxes (also referred to as ports).
        • Each mailbox has a unique id.
        • Processes can communicate only if they share a mailbox.
      • Primitives used:
        • Send (A, message) – send a message to mailbox A.
        • Receive (A, message) – receive a message from mailbox A.
    35. Indirect communication
      • Properties of communication link for this scheme:
        • 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.
      • Operations:
        • Create a new mailbox.
        • Send and receive messages through mailbox.
        • Destroy a mailbox.
    36. Indirect communication ….
      • Mailbox sharing If processes P1, P2, and P3 share a mailbox A, and process P1 sends a message to mailbox A while processes P2 and P3 execute a receive from A, which process will receive the message sent by P1?
      • Three possible solutions:
        • Allow a link to be associated with at most two processes.
        • Allow only one process at a time to execute a receive operation.
        • Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was.
    37. Synchronization
      • Message passing can be either blocking ( synchronous ) or nonblocking (asynchronous).
      • Blocking send: The sender is blocked until the message is received.
      • Nonblocking send: the sender resumes operation after sending the message.
      • Blocking receive: the receiver blocks until message is available.
      • Nonblocking receive: receiver retrieves either a valid message or a NULL.
    38. Buffering
      • Whether the communication is direct or indirect, messages exchanged by communicating processes reside in a temporary queue. Such a queue can be implemented in three ways
        • zero capacity
        • bounded capacity
        • unbounded capacity
      • For the non-zero capacity case, the sender does not know if a message has arrived at the destination (may use asynchronous communication; the receiver sends back an acknowledgement to the sender.)
    39. Exception conditions – error recovery
      • An Error may occur during process communications;
      • When a failure occurs, some error recovery must takes place.
        • Process terminates
        • E xample: process P is waiting for a message from a terminated process Q.
        • Solution: OS terminates P or notify P that Q has terminated.
    40. Exception conditions – error recovery
        • Lost messages
        • Example: message from P to Q become lost due to hardware error;
        • Solution:
          • OS detects it and resend the message.
          • Sender detects it and resend.
          • OS detects it and let the sender know.
        • Scrambled messages
        • Example: message is received but in error; detected by parity checking, CRC.
        • Solution: resend it.
    41. Communication in Client-Server Systems
      • Sockets
        • A socket is defined as an endpoint for communication .
        • Concatenation of IP address and port.
        • The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8
        • Communication consists between a pair of sockets.
    42. Socket Communication
    43. Remote Procedure Calls
      • Remote procedure call (RPC) abstracts procedure calls between processes on networked systems.
      • Stubs – client-side proxy for the actual procedure on the server.
      • The client-side stub locates the server and marshalls the parameters.
      • The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server.
    44. Execution of RPC
    45. Remote Method Invocation (RMI)
      • Remote Method Invocation is a Java mechanism similar to RPCs.
      • RMI allows a Java program on one machine to invoke a method on a remote object.
    46. Marshalling Parameters
    47.  
    48.  
    49. Thank You
    SlideShare Zeitgeist 2009

    + Raj NOXRaj NOX Nominate

    custom

    370 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 370
      • 370 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 24
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories