1 / 30

Operating Systems

Part III: Process Management ( Process States and Transitions ). Operating Systems. Process Definition. Definition ( informal ): A process is a program in execution Referred to as a job in batch systems and user program / task in time-shared systems

duard
Download Presentation

Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Part III: Process Management (Process States and Transitions) Operating Systems

  2. Process Definition Definition (informal): A process is a program in execution Referred to as a job in batch systems and user program / task in time-shared systems More broadly: all CPU activities (includes user programs, internal O/S activities, etc.)

  3. Process States Processes are executed sequentially Process States: New: process is being created Running: instructions are being executed Waiting: waiting for an event (i.e. I/O completion) Ready: waiting to be assigned to a processor Terminated: process has finished execution

  4. Process States terminated new running ready waiting exit admitted interrupt scheduler dispatch I/O or event wait I/O or event completion

  5. Process Control Block Each process is represented by a process control block (PCB) Information contained in PCB: Process state Program counter: address of next instruction CPU registers: accumulators, index registers, stack pointers -- must be saved when interrupt occurs

  6. Process Control Block Information in PCB (continued) CPU scheduling information - process priority & scheduling parameters Memory-management information - page tables, etc. Accounting information - amount of CPU USED I/O status information - list of I/O devices allocated to this process, list of open files, etc.

  7. Process Scheduling Processes are put in a job queue (consists of all processes) Processes residing in main memory (ready and waiting) are kept in ready queue Uni-processor (only one running process at a time); multiprocessor (# of processes running depend on # of processors)

  8. Process Scheduling Long-term scheduler (a.k.a. job scheduler) - selects processes from mass storage device and loads into main memory for execution Short-term scheduler (a.k.a. CPU scheduler) - selects from ready to execute processes and allocates CPU to one of them

  9. Process Scheduling CPU-bound process - spends more time doing computation I/O-bound process - spends more time doing I/O Medium-term scheduler - removes some processes in main memory and then later reintroduced to continue execution --> also called swapping

  10. Process Scheduling Portion of Virtual Memory Ready Queue (Ready) CPU (Running) Job Queue (New) Main Memory I/O Queue (Waiting) I/O Exit (Terminated) medium - term scheduler / swapper interrupt long - term / job scheduler short - term / CPU scheduler I/O request I/O complete Secondary Memory

  11. Process Scheduling Context switch CPU switching from one process to another Purely overhead because system does no useful work Value of registers must be copied to PCB Speed ranges vary from machine to machine (but typically 1 to 1000 microseconds)

  12. Operation in Processes Process creation Created via a create-process system call Creating process is the parent process and the new process is the child process Forms a tree of processes

  13. Operation in Processes Process creation (continued) Two possibilities (execution) Parent continues to run concurrently w/ children Parent waits until some/all children have finished Two possibilities (address space) Child has duplicate of parent address space Child has program loaded into parent address space

  14. Operation in Processes Process creation (continued) In Unix, new process is created using the fork system call Parent continues execution Copy of address space is created Also in Unix, execve is similar to fork except Parent “dies” Memory space replaced by child

  15. Operation in Processes Process termination Normally terminates w/ exit system call (Unix) All resources are deallocated by O/S Other circumstances Parent terminates child (i.e. abort) Child exceeded usage of resources Child is no longer required Parent is exiting, O/S does not allow child to exist without parent Process killed by other processes (user’s own)

  16. Cooperating Processes Independent process - cannot affect or be affected by other processes (does not share any data) Dependent process - if it can affect or be affected by other processes (shares data with other processes)

  17. Cooperating Processes Reasons for sharing data w/ other processes Information sharing Computation speedup - break complex task into subtasks Modularity - divide a system into separate processes Convenience - work on many tasks at the same time (editing/printing/compiling)

  18. Cooperating Processes An illustration Producer-consumer problem: producer produces information for the consumer to consume (i.e. print program and printer device) Unbounded-buffer -> no limit on size of buffer but consumer has to wait for new items Bounded-buffer -> fixed buffer (consumer waits if buffer is empty, producer if full)

  19. Threads Allows sharing of resources among peers Also called a lightweight process (LWP) Has a program counter, register set, and stack space Shares with peer threads its code section, data section, O/S resources (collectively known as a task)

  20. Threads Traditional task (heavyweight process) has exactly one thread Threads makes CPU switching among peers less expensive than among heavyweight processes (no memory mgt.)

  21. Threads Similar to processes since a thread has states (ready, running, blocked, terminated) can create child threads shares CPU

  22. Threads Unlike a process, threads are not independent of each other can access every address in the task have no protection from other threads since threads are meant to assist and not be hostile to one another Threads are gaining ground because they execute more efficiently

  23. Interprocess Communication Cooperating processes communicate through a shared-memory environment Another means is through an interprocess-communication (IPC) facility Achieved through a messaging system Function of message system is to allow process communication without resorting to shared variables

  24. Interprocess Communication IPC provides at least two basic functions: send(message) receive(message) A communication link must exist between two or more processes Unidirectional link – can either send or receive but NOT BOTH and each link has at least one receiver process connected to it

  25. Interprocess Communication Processes refer to each other through names Name referencing is used in direct and indirect communication Direct communication send(process_name,message) receive(process_name,message) The link is exactly between two processes and usually bi-directional (sometimes unidirectional)

  26. Interprocess Communication Direct communication (continued) Example: Producer-consumer problem: when producer finishes, it sends to the consumer Symmetric – sender and receiver indicate process name Asymmetric – only the sender specifies the process name; receiver can receive message from any process Disadvantage: limited modularity (e.g. when process changes name)

  27. Interprocess Communication Indirect communication Messages sent through a mailbox send(mailbox_name,message) receive(mailbox_name,message) Link is established between processes ONLY through a shared mailbox Mailbox may be owned by either the process or the system Mailboxes owned by the process are destroyed when process terminates

  28. Interprocess Communication Buffering Link capacity determines number of messages that can reside in it temporarily Zero capacity No messages can wait in buffer Sender waits until recipient receives Must be synchronized to transfer a message (rendezvous)

  29. Interprocess Communication Buffering (continued) Bounded capacity With finite length n Sender waits if buffer is full Unbounded capacity Sender never delays

  30. Communication in Client-Server Systems Socket An endpoint for communication A link consists of two sockets RPC (Remote Procedure Call) Allows a local process to invoke a procedure on a remote host as if accessing a local procedure RMI (Remote Method Invocation) The Java implementation of RPC

More Related