My ppt @ bec doms on process management


Published on

My ppt @ bec doms on process management

Published in: Business, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • 10 The operating system main responsibility is to control the execution of processes. In other words, it is suppose to determine the interleaving pattern for execution and allocating resources to the process. A simple model with two states per process can be used to describe the behavior of a process. The state transition diagram of a process is presented in this slide. When the OS creates a new process, it enters it into the Not Running state; after that, the process exists, is known to the OS and waits for the opportunity to run From time to time, the currently running process will be interrupted and the dispatcher process will select a new process to run; The former process is brought into Not Running state, and the new process will be moved to Running state.
  • 11 From the two states process model, we already start to appreciate some of design elements of an Operating System. Each of the processes needs to be represented in some way, so the operating system can keep track of it. There must be some information rating to each process, i.e. current state and location in memory. Processes that are not running must be kept in some sort of queue, waiting their turn to execute.
  • 12 Regardless of the used model, the life of a process is bounded by its creation and its termination
  • 15 If all processes were always ready to execute, than the queuing discipline suggested so far would be effective. The queue was first in first out and the processor operates in round robin fashion on the available processes (each process in the queue it is given an certain amount of time, in turn, to execute and then returned to the queue). The two state model is in fact not accurate, because some of the processes in the Not Running state are ready to execute, while some others are suspended, waiting for the completion of an I/O operation.
  • 16 The process manager uses the state diagram to determine what type of service to provide to the process. If process is in ready state then it is competing for the CPU time; there is no other transition from this state but to be scheduled (or dispatched) and become active or running If process is active or running , the process can: Complete its execution, transitioning in exit state May request an I/O operation: If the requested resource is available immediately, then the execution can continue If the requested resource is not immediate, the process manager notifies the resource manager that the process requires units of its resource; the process goes in suspended or blocked mode waiting for an resource allocation event; the scheduler/dispatcher is invoked to chose the next process to become active from the ready process list The process may be interrupted due to some external event (i.e. exceeded the allocated CPU time) and is taken into ready state If the process is in blocked state, the process can move into ready state when it is being allocated the requested resource or when an external event occurs; it then competes again for the processor
  • 18 When an event appears, the operating system has to scan the whole blocked queue and figure out which process is waiting on that event … this can be very inefficient in large operating systems (where the blocked queue can have a few thousands entries)
  • 22 Memory tables – used to keep track of both main (real) and secondary (virtual) memory. Some of main memory is reserved for use by the operating system; the remainder is available to the processes. I/O tables are used by the operating system to manage the I/O devices. File tables are used to manage the files and accesses to the files. Primary process table is used to keep one entry per each process in the operating system. Each entry contains at least one pointer to a process image. The Process Image contains data, code, stack and process control block (attributes and information about process) associated with a process. Those tables are linked (even if not shown) or cross referenced. Memory, Files and I/O are managed in behalf of processes, so there must be some reference to those resources in the processes tables (direct or indirect references). Those tables are created whenever the operating system is initialized (so the operating system must know about the physical environment it operates in, i.e. how much physical RAM is available, etc…).
  • 33 In this slide, each process appears as contiguous range of addresses. In an actual implementation, this may not be the case. It will depend on the memory management scheme and the way in which control structures are organized by the operating system.
  • 35 Hardware support: Multiple registers set, one per mode, no need for save / restore of user registers Existence of an address space that can be automatically mapped in protected mode and not accessible in user mode
  • 44 Unix employs two RUNNING states to indicate whether the process is executing in user mode or kernel mode.
  • 45 Preempted and Ready to run, in memory are nearly identical A process may be preempted for a higher-priority process at the end of a system call. Preemption can only occur when a process is about to move from kernel mode to user mode. While a process is running in kernel mode, it may not be preempted. This makes UNIX unsuitable for real time processing. Zombie – Saves information to be passed to the parent of this process. Two processes are unique in UNIX: Process 0 – Swapper , created at boot time Process 1 – Init , creates other processes and it is spawned by process 0.
  • 49 Process table entry and the U area are detailed next.
  • 50 This process table is maintained by the operating system, with one entry per process. It contains process control information that is accessible to the kernel at all times; hence in a virtual memory system, all process table entries are maintained in the main memory (to be fast accessible).
  • 51 The user area contains additional control information that is needed by the kernel when it is executing in the context of this process. The distinction between the process table entry and the U area reflects the fact that UNIX kernel always executes in the context of some process. Much of the time, the kernel will deal with concerns of that process. However, some of the time, such as when scheduling is performed, it will need access to information about other processes.
  • 52 All of this happens in the parent process, in kernel mode. When the kernel has completed those functions, it will one of the following things: Will return to user mode in the parent process, at the point of fork() Transfer control to the child process. The child code will start executing at the return point from the fork call Transfer control to another process. Both parent and the child are left in the Ready to Run stte.
  • 53 Characteristics of Processes Implemented as objects May contain one or more threads Both processes and threads have built-in synchronization capabilities
  • 54 Each process is represented by an object (in the slide). Each process is defined by a number of attributes and encapsulates a number of actions (services) that it may perform. A process will perform a service by receiving a message (the only way of invoking such a service is by means of messages). Each process must contain at least one thread. The thread object structure is represented in the slide. Multithreading Threads in the same process can execute concurrently Symmetric MultiProcessor Support Any thread (including kernel threads) can run on any processor Soft affinity – Try to reschedule a thread on the same processor Hard affinity – Restrict a thread to certain processors
  • 55 Thread States: Ready – Able to run Standby – Scheduled to run Running Waiting – Blocked or suspended Transition – Not blocked, but can’t run (paged out of memory) Terminated Support for O.S. Subsystem Process creation Begins with request from application Goes to protected subsystem Passed to executive, returns handle Win32 use handle to create thread Return process/thread information Win2000 - client requests a new thread Thread inherits limits, etc. from parent
  • 57 Running – either executing or ready to execute (made out of two states) Interruptible – this is a blocked state, in which the process is waiting for an event, such as the end of an I/O operation, the availability of a resource or a signal from another process Uninterruptible – this is another blocked state. The difference between this and the previous is that here a process is waiting directly on hardware conditions and therefore will not accept any signals. Stopped – the process has been halted and can be resumed only by positive action from another process (i.e. a process that is being debugged can be stopped by another process- the debugger). Zombie – process has been terminated but still must have its task structure in the task list (process table).
  • My ppt @ bec doms on process management

    1. 1. Process Management
    2. 2. Content <ul><li>Process – operating system view </li></ul><ul><ul><li>Process management </li></ul></ul><ul><ul><li>Process states </li></ul></ul><ul><ul><li>Process description </li></ul></ul><ul><ul><li>Process control </li></ul></ul><ul><ul><ul><li>Process creation/termination </li></ul></ul></ul><ul><ul><ul><li>Process switch </li></ul></ul></ul><ul><li>Threads </li></ul><ul><li>Operating system services for process management </li></ul><ul><li>UNIX Process Management </li></ul><ul><li>Win 2k Process and Thread Management </li></ul><ul><li>Linux Process and Thread Management </li></ul>
    3. 3. Process management <ul><li>Process components: </li></ul><ul><ul><li>A program to define the behavior of the process </li></ul></ul><ul><ul><li>The data operated on by the process and the results it produces </li></ul></ul><ul><ul><li>A set of resources to provide an environment for the execution </li></ul></ul><ul><ul><li>A status record to keep track of the progress and control of the process during execution </li></ul></ul><ul><li>Process manager functions: </li></ul><ul><ul><li>Implements CPU sharing (called scheduling ) </li></ul></ul><ul><ul><li>Must allocate resources to processes in conformance with certain policies </li></ul></ul><ul><ul><li>Implements process synchronization and inter-process communication </li></ul></ul><ul><ul><li>Implements deadlock strategies and protection mechanisms </li></ul></ul>
    4. 4. Process management
    5. 5. Process States (1) <ul><li>The principal function of a processor is to execute machine instructions residing in main memory </li></ul><ul><ul><li>Those instructions are provided in the form of programs </li></ul></ul><ul><ul><li>A processor may interleave the execution of a number of programs over time </li></ul></ul><ul><li>Program View </li></ul><ul><ul><li>Its execution involves a sequence of instructions within that program </li></ul></ul><ul><ul><li>The behavior of individual process can be characterized by a list of the sequence of instructions – trace of the process </li></ul></ul><ul><li>Processor View </li></ul><ul><ul><li>Executes instructions from main memory, as dictated by changing values in the program counter register </li></ul></ul><ul><ul><li>The behavior of the processor can be characterized by showing how the traces of various processes are interleaved </li></ul></ul>
    6. 6. Process States (2) <ul><li>Consider three processes: A, B and C that are loaded in memory; In addition there is a small dispatcher program that switches the processor from one process to another </li></ul><ul><li>No use of virtual memory </li></ul><ul><li>Process B invokes an I/O operation in the fourth instruction </li></ul><ul><li>First 12 instructions in process A and B are shown </li></ul><ul><li>Operating system allows a process to monopolize the processor for only 6 instructions </li></ul>
    7. 7. Memory Layout <ul><li>Snapshot at instruction cycle 13 </li></ul>
    8. 8. Traces of Processes A, B and C (Processes View)
    9. 9. Combined Trace of Processes (Processor View)
    10. 10. Two State Process Model <ul><li>Simple two state process model </li></ul><ul><ul><li>The process can be in one of two states: running or not running </li></ul></ul><ul><ul><li>When the OS creates a new process, it enters it into the Not Running state; after that, the process exists, is known to the OS and waits for the opportunity to run </li></ul></ul><ul><ul><li>From time to time, the currently running process will be interrupted and the dispatcher process will select a new process to run </li></ul></ul><ul><ul><li>The new process will be moved to Running state and the former one to Not Running state </li></ul></ul>
    11. 11. Queuing Discipline <ul><li>Each process needs to be represented </li></ul><ul><ul><li>Info relating to each process, including current state and location in memory </li></ul></ul><ul><ul><li>Waiting processes should be kept in some sort of queue </li></ul></ul><ul><ul><ul><li>List of pointers to processes blocks </li></ul></ul></ul><ul><ul><ul><li>Linked list of data blocks; each block representing a process </li></ul></ul></ul><ul><li>Dispatcher behavior: </li></ul><ul><ul><li>An interrupted process is transfred in waiting queue </li></ul></ul><ul><ul><ul><li>If process is completed or aborted, it is discarded </li></ul></ul></ul><ul><ul><li>The dispatcher selects a process from the queue to execute </li></ul></ul>
    12. 12. Process Creation <ul><li>Creation of new process: </li></ul><ul><ul><li>The OS builds the data structures that are used to manage the process </li></ul></ul><ul><ul><li>The OS allocates space in main memory to the prcess </li></ul></ul><ul><li>Reasons for process creation: </li></ul><ul><ul><li>New batch job </li></ul></ul><ul><ul><li>Interactive logon </li></ul></ul><ul><ul><li>Created by OS to provide a service </li></ul></ul><ul><ul><ul><li>i.e. process to control printing </li></ul></ul></ul><ul><ul><li>Spawned by existing process </li></ul></ul><ul><ul><ul><li>i.e. to exploit parallelism </li></ul></ul></ul>
    13. 13. Process Termination <ul><li>Reasons for process termination </li></ul><ul><ul><li>Process finished its execution (natural completion) </li></ul></ul><ul><ul><li>Total time limit exceeded </li></ul></ul><ul><ul><li>Errors (memory unavailable, aritmetic error, protection error, invalid instruction, privilegied instruction, I/O failure, etc…) </li></ul></ul><ul><ul><li>Parent termination </li></ul></ul><ul><ul><ul><li>When the parent terminates, the OS may automatically terminate all of its children </li></ul></ul></ul><ul><ul><li>Parent request </li></ul></ul><ul><ul><ul><li>A parent has typically the right to request a child termination </li></ul></ul></ul>
    14. 14. Resource manager <ul><li>Reusable resources - resources that can be allocated and must be returned to the system after the process has finished; fixed, finite number (such as a block of memory) </li></ul><ul><li>Consumable resources – abstract resources such as data input; unbounded number; a process can create consumable resource (such as messages) by releasing one or more units of the resources; a receiver process will be queued on that resource type; if there is no resource of that type, then the resource count is 0 and the process is blocked on the resource; when another process sends an message, the message handling code release a unit of the resource type to the resource manager; the resource manager can allocate the unit of resource to the requesting process so that it can proceed in ready state to compete for the CPU </li></ul>
    15. 15. Five State Model <ul><li>Running – The process is currently being executed </li></ul><ul><ul><li>For single processor systems, one single process can be in this state at a time </li></ul></ul><ul><li>Ready – a process that is prepared to execute when given the turn </li></ul><ul><li>Blocked – a process that can’t execute until some event occurs </li></ul><ul><ul><li>Such as the completion of an I/O operation </li></ul></ul><ul><li>New – a process that has been created, but not yet accepted in the pool of executable processes by OS </li></ul><ul><ul><li>Typically, a new process has not yet been loaded into main memory </li></ul></ul><ul><li>Exit – a process that has been released from the pool of executable processes by the OS </li></ul><ul><ul><li>Completed or due to some errors </li></ul></ul>
    16. 16. Five State Model Process Transition Diagram
    17. 17. Our Example <ul><li>Movement of each process described earlier (A, B and C) among the states </li></ul>
    18. 18. Queuing Discipline (1) <ul><li>There are two queues now: ready queue and blocked queue </li></ul><ul><ul><li>When the process is admitted in the system, it is placed in ready queue </li></ul></ul><ul><ul><li>When a process is removed from the processor, it is either placed in ready queue or in blocked queue (depending on circumstances) </li></ul></ul><ul><ul><li>When an event occurs, all the processes waiting on that event are moved from blocked queue onto ready queue. </li></ul></ul>
    19. 19. Queuing Discipline (2) <ul><li>Multiple blocked queues; one per each event </li></ul><ul><ul><li>When event occurs, the entire list of processes is moved in ready queue </li></ul></ul>
    20. 20. Suspended Processes <ul><li>Processor is faster than I/O so all processes could be waiting for I/O </li></ul><ul><li>Swap these processes to disk to free up more memory </li></ul><ul><li>Blocked state becomes suspend state when swapped to disk </li></ul>
    21. 21. Process Description <ul><li>What information does the operating system need to control processes and manage resource for them? </li></ul><ul><li>Operating System Control Structures </li></ul><ul><ul><li>Memory Tables </li></ul></ul><ul><ul><li>I/O Tables </li></ul></ul><ul><ul><li>File Tables </li></ul></ul><ul><ul><li>Primary Process Table </li></ul></ul><ul><ul><li>Process Image </li></ul></ul><ul><ul><ul><li>User Program, user data, stack and attributes of the process </li></ul></ul></ul>
    22. 22. Operating System Control Structures
    23. 23. Memory Tables <ul><li>Used to keep track of both main (real) and secondary (virtual) memory. Some of main memory is reserved for use by the operating system; the remainder is available to the processes. </li></ul><ul><li>Contain: </li></ul><ul><ul><li>The allocation of main memory to processes </li></ul></ul><ul><ul><li>The allocation of secondary memory to processes </li></ul></ul><ul><ul><li>Any protection attributes of blocks of main or virtual memory (such as which processes can access certain shared memory regions) </li></ul></ul><ul><ul><li>Any information needed to manage virtual memory </li></ul></ul>
    24. 24. I/O tables <ul><li>Are used by the operating system to manage the I/O devices </li></ul><ul><ul><li>At any given time, an I/O device may be available or assigned to a particular process. </li></ul></ul><ul><ul><li>If an I/O is in progress, the OS needs to know the status of the I/O operation and the location in main memory being used as the source or destination of the I/O transfer. </li></ul></ul>
    25. 25. File Tables <ul><li>These tables provide information about: </li></ul><ul><ul><li>the existence of files </li></ul></ul><ul><ul><li>their location on secondary memory </li></ul></ul><ul><ul><li>their current status </li></ul></ul><ul><ul><li>other attributes </li></ul></ul><ul><li>Much of this information is maintain and managed by the File Manager, in which case the process manager has little or no knowledge of files. </li></ul>
    26. 26. Process Tables <ul><li>Primary process table is used to keep one entry per each process in the operating system. Each entry contains at least one pointer to a process image. </li></ul><ul><li>The Process Image contains: </li></ul><ul><ul><li>User Data </li></ul></ul><ul><ul><ul><li>Program data that can be modified, etc… </li></ul></ul></ul><ul><ul><li>Code </li></ul></ul><ul><ul><ul><li>The sequence of instructions (program) to be executed </li></ul></ul></ul><ul><ul><li>Stack </li></ul></ul><ul><ul><ul><li>Each process has one or more stacks associated with it. A stack is used to store parameters and calling addresses for procedure and system calls </li></ul></ul></ul><ul><ul><li>Process control block </li></ul></ul><ul><ul><ul><li>Data needed by the operating system to control the process (attributes and information about process) </li></ul></ul></ul>
    27. 27. Process Control Block <ul><li>Contains: </li></ul><ul><ul><li>Process Identification </li></ul></ul><ul><ul><li>Processor State Information </li></ul></ul><ul><ul><li>Process Control Information </li></ul></ul>
    28. 28. Process Identification <ul><li>Identifiers </li></ul><ul><ul><li>Numeric identifiers that may be stored with the process control block include: </li></ul></ul><ul><ul><ul><li>Identifier of this process </li></ul></ul></ul><ul><ul><ul><li>Identifier of the process that created this process (parent process) </li></ul></ul></ul><ul><ul><ul><li>User identifier </li></ul></ul></ul>
    29. 29. Processor State Information <ul><li>User-Visible Registers </li></ul><ul><ul><li>A user-visible register is one that may be referenced by means of the machine language that the processor executes. Typically, there are from 8 to 32 of these registers, although some RISC implementations have over 100. </li></ul></ul><ul><li>Control and Status Registers </li></ul><ul><ul><li>These are a variety of processor registers that are employed to control the operation of the processor. These include: </li></ul></ul><ul><ul><ul><li>Program counter: Contains the address of the next instruction to be fetched </li></ul></ul></ul><ul><ul><ul><li>Condition codes: Result of the most recent arithmetic or logical operation (e.g., sign, zero, carry, equal, overflow bits) </li></ul></ul></ul><ul><ul><ul><li>Status information: Includes interrupt enabled/disabled flags, execution mode </li></ul></ul></ul><ul><li>Stack Pointers </li></ul><ul><ul><li>Each process has one or more last-in-first-out (LIFO) system stacks associated with it. A stack is used to store parameters and calling addresses for procedure and system calls. The stack pointer points to the top of the stack. </li></ul></ul>
    30. 30. Process Control Information (1) <ul><li>Scheduling and State Information </li></ul><ul><ul><li>This is information that is needed by the operating system to perform its scheduling function. Typical items of information: </li></ul></ul><ul><ul><ul><li>Process state: defines the readiness of the process to be scheduled for execution (e.g., running, ready, waiting, halted). </li></ul></ul></ul><ul><ul><ul><li>Priority: One or more fields may be used to describe the scheduling priority of the process. In some systems, several values are required (e.g., default, current, highest-allowable) </li></ul></ul></ul><ul><ul><ul><li>Scheduling-related information: This will depend on the scheduling algorithm used. Examples are the amount of time that the process has been waiting and the amount of time that the process executed the last time it was running. </li></ul></ul></ul><ul><ul><ul><li>Event: Identity of event the process is awaiting before it can be resumed </li></ul></ul></ul>
    31. 31. Process Control Information (2) <ul><li>Data Structuring </li></ul><ul><ul><li>A process may be linked to other process in a queue, ring, or some other structure. For example, all processes in a waiting state for a particular priority level may be linked in a queue. A process may exhibit a parent-child (creator-created) relationship with another process. The process control block may contain pointers to other processes to support these structures. </li></ul></ul><ul><li>Interprocess Communication </li></ul><ul><ul><li>Various flags, signals, and messages may be associated with communication between two independent processes. Some or all of this information may be maintained in the process control block. </li></ul></ul><ul><li>Process Privileges </li></ul><ul><ul><li>Processes are granted privileges in terms of the memory that may be accessed and the types of instructions that may be executed. In addition, privileges may apply to the use of system utilities and services. </li></ul></ul>
    32. 32. Process Control Information (3) <ul><li>Memory Management </li></ul><ul><ul><li>This section may include pointers to segment and/or page tables that describe the virtual memory assigned to this process. </li></ul></ul><ul><li>Resource Ownership and Utilization </li></ul><ul><ul><li>Resources controlled by the process may be indicated, such as opened files. </li></ul></ul><ul><ul><li>A history of utilization of the processor or other resources may also be included; this information may be needed by the scheduler. </li></ul></ul>
    33. 33. Process Images in Virtual Memory
    34. 34. Process Creation <ul><li>Assign a unique process identifier </li></ul><ul><li>Allocate space for the process </li></ul><ul><li>Initialize process control block </li></ul><ul><li>Set up appropriate linkages </li></ul><ul><ul><li>Ex: add new process to linked list used for scheduling queue </li></ul></ul><ul><li>Create of expand other data structures </li></ul><ul><ul><li>Ex: maintain an accounting file </li></ul></ul>
    35. 35. Process switch <ul><li>Switching the processor control from one process to another (due to occurrence and service of an event) is known as process switch </li></ul><ul><li>Process switch stages: </li></ul><ul><ul><li>Event occurrence </li></ul></ul><ul><ul><li>Mode switch (user->kernel) </li></ul></ul><ul><ul><ul><li>Event service (see what event and take appropriate action) </li></ul></ul></ul><ul><ul><li>Choose the next active process </li></ul></ul><ul><ul><li>Save context of the current active process (PC, PSW, registers, etc..) </li></ul></ul><ul><ul><li>Update PCB for current active process </li></ul></ul><ul><ul><li>Update PCB lists </li></ul></ul><ul><ul><li>Restore active state for next process </li></ul></ul><ul><ul><li>Mode switch (kernel -> user) </li></ul></ul><ul><li>Process switch is very frequent in multiprogramming systems, affecting system performance, so it has to be done fast </li></ul>
    36. 36. Possible Reasons for Process Switch <ul><li>Clock interrupt </li></ul><ul><ul><li>process has executed for the maximum allowable time slice </li></ul></ul><ul><li>I/O interrupt </li></ul><ul><li>Memory fault </li></ul><ul><ul><li>memory address is in virtual memory so it must be brought into main memory </li></ul></ul><ul><li>Trap </li></ul><ul><ul><li>error occurred </li></ul></ul><ul><ul><li>may cause process to be moved to Exit state </li></ul></ul>
    37. 37. Threads and Processes <ul><li>A process is defined sometime a heavyweight process ; a thread is defined as a lightweight process ; </li></ul><ul><li>Separate two ideas: </li></ul><ul><ul><li>Process: Ownership of memory, files, other resources </li></ul></ul><ul><ul><li>Thread: Unit of execution we use to dispatch </li></ul></ul><ul><li>Multithreading </li></ul><ul><ul><li>Allow multiple threads per process </li></ul></ul>
    38. 38. Threads (1) <ul><li>It is a unit of computation associated with a particular heavyweight process, using many of the associated process’s resources (has a minimum of internal state and a minimum of allocated resources) </li></ul><ul><li>A group of threads are sharing the same resources (files, memory space, etc) </li></ul><ul><li>The process is the execution environment for a family of threads; a process with one thread is a classic process </li></ul><ul><li>A thread belongs only to one process </li></ul>
    39. 39. Threads (2) <ul><li>Individual execution state </li></ul><ul><li>Each thread has a control block, with a state (Running/Blocked/etc.), saved registers, instruction pointer </li></ul><ul><li>Separate stack and hardware state (PC, registers, PSW, etc) per thread </li></ul><ul><li>Shares memory and files with other threads that are in that process </li></ul><ul><li>Faster to create a thread than a process </li></ul><ul><li>Because the a family of threads belonging to the same process have common resources, the thread switch is very efficient </li></ul><ul><li>Thread switch for threads from different processes is as complex as classic process switch </li></ul>
    40. 40. Threads <ul><li>The threads are using many of the associated heavyweight process’s resources (especially the object program code – instructions) </li></ul><ul><li>Widely used in real time operating systems and modern operating systems </li></ul>
    41. 41. Using threads
    42. 42. Process management services <ul><li>create (&process_id, attributes) </li></ul><ul><ul><li>Creates a new process with implicit or specified attributes </li></ul></ul><ul><li>delete (process_id) </li></ul><ul><ul><li>Sometime known as destroy, terminate or exit </li></ul></ul><ul><ul><li>Finishes the process specified by process_id </li></ul></ul><ul><ul><li>Whenever the process is terminated, all the files are closed, all the allocated resources are released </li></ul></ul><ul><li>abort (process_id) </li></ul><ul><ul><li>same as the delete but for abnormal termination </li></ul></ul><ul><ul><li>Usually generates an :post mortem dump” which contains the state of the process before the abnormal termination </li></ul></ul><ul><li>suspend (process_id) </li></ul><ul><ul><li>Determines the specified process to go in suspended state </li></ul></ul>
    43. 43. Process management services… <ul><li>resume (process_id) </li></ul><ul><ul><li>Determines the specified process to go from the suspended state in ready state </li></ul></ul><ul><li>delay (process_id, time) </li></ul><ul><ul><li>Same with sleep </li></ul></ul><ul><ul><li>Suspends the specified process for the specified period of time </li></ul></ul><ul><ul><li>After the delay time elapses, the process is brought to ready state </li></ul></ul><ul><li>get_attributes (process_id, &buffer_attributes) </li></ul><ul><ul><li>Used to find out the attributes for the given process </li></ul></ul><ul><li>set_attributes (process_id, buffer_attributes) </li></ul><ul><ul><li>Used to set the attributes of the specified process </li></ul></ul>
    44. 44. UNIX Process States
    45. 46. UNIX – Process Image <ul><li>User Level Context </li></ul><ul><li>Register Context </li></ul><ul><li>System Level Context </li></ul>
    46. 47. Unix – User Level Context <ul><li>Contains the basic elements of a user’s program and it is usually generated from a compiled object file </li></ul><ul><ul><li>User Code </li></ul></ul><ul><ul><ul><li>Read only and is intended to hold the program's instructions </li></ul></ul></ul><ul><ul><li>User Data </li></ul></ul><ul><ul><ul><li>Data accessible and processed by this process </li></ul></ul></ul><ul><ul><li>User Stack </li></ul></ul><ul><ul><ul><li>Used while executing in user mode for procedure calls and returns and parameter passing </li></ul></ul></ul><ul><ul><li>Shared Memory </li></ul></ul><ul><ul><ul><li>Data area shared with other processes; there is just one physical copy of shared area </li></ul></ul></ul>
    47. 48. UNIX – Register Context <ul><li>When a process is not running, the processor status information is stored in the register context area </li></ul><ul><ul><li>Program Counter </li></ul></ul><ul><ul><ul><li>May be in either user or kernel space </li></ul></ul></ul><ul><ul><li>PSW (Processor Status Word) </li></ul></ul><ul><ul><li>Stack Pointer </li></ul></ul><ul><ul><ul><li>Points to top of user/kernel stack </li></ul></ul></ul><ul><ul><li>General Registers </li></ul></ul>
    48. 49. UNIX – System Level Context <ul><li>Contains the remaining information that the operating system needs to manage the process </li></ul><ul><li>Contains </li></ul><ul><ul><li>A static part – stays at the same size during a process lifetime </li></ul></ul><ul><ul><ul><li>Process table entry </li></ul></ul></ul><ul><ul><ul><li>U area </li></ul></ul></ul><ul><ul><ul><li>Per process region table </li></ul></ul></ul><ul><ul><ul><ul><li>Used by the memory management system (contains virtual memory info) </li></ul></ul></ul></ul><ul><ul><li>A dynamic part </li></ul></ul><ul><ul><ul><li>Kernel Stack - this stack is used when the process is executing in kernel mode and contains information that must be saved and restored as procedure calls and interrupts occur </li></ul></ul></ul>
    49. 50. UNIX - Process Table Entry <ul><li>Status – Current state of a process </li></ul><ul><li>Pointers to U area and user code/data </li></ul><ul><li>Process size </li></ul><ul><li>Identifiers (real/effective user/group id) </li></ul><ul><li>Process/Parent ID </li></ul><ul><li>Event Descriptor </li></ul><ul><li>Signal – Signals sent but not handled </li></ul><ul><li>Priority </li></ul><ul><li>Timers - process execution time, user-set alarm </li></ul><ul><li>Memory status – Is it swapped out? </li></ul>
    50. 51. UNIX – U Area <ul><li>Identifiers (real/effective user/group id) </li></ul><ul><li>Timers (time spent in user/kernel mode) </li></ul><ul><li>Signal Handler array </li></ul><ul><li>Control terminal (if it exists) </li></ul><ul><li>System call return value </li></ul><ul><li>System call errors </li></ul><ul><li>I/O and File parameters </li></ul><ul><li>File Descriptor information </li></ul><ul><li>Permission Mode Field </li></ul><ul><li>Limit on process size </li></ul>
    51. 52. UNIX – Process Creation <ul><li>By means of system call fork() </li></ul><ul><li>When a fork is issues, the OS performs the following operations: </li></ul><ul><ul><li>Allocates a slot in the process table for the new process </li></ul></ul><ul><ul><li>Assigns a unique process ID to the child process </li></ul></ul><ul><ul><li>Makes a copy of the process image of the parent </li></ul></ul><ul><ul><ul><li>With the exception of any shared memory </li></ul></ul></ul><ul><ul><li>Increments counters for any files owned by the parent </li></ul></ul><ul><ul><li>Assigns the child process to a Ready to Run state </li></ul></ul><ul><ul><li>It returns the ID number of the child to the process parent a value 0 to the child process </li></ul></ul>
    52. 53. Windows 2k Processes <ul><li>Characteristics of Processes </li></ul><ul><ul><li>Implemented as objects </li></ul></ul><ul><ul><li>May contain one or more threads </li></ul></ul><ul><ul><li>Both processes and threads have built-in synchronization capabilities </li></ul></ul>
    53. 54. Windows 2k Process and Thread Objects
    54. 55. Windows Process and Thread Management <ul><li>Windows 2k Thread States </li></ul>
    55. 56. Linux Process Management <ul><li>Task structure maintained for each process </li></ul><ul><ul><li>State (executing, ready, zombie, etc.) </li></ul></ul><ul><ul><li>Scheduling information </li></ul></ul><ul><ul><li>Process, user, group identifiers </li></ul></ul><ul><ul><li>Inter-process communication info </li></ul></ul><ul><ul><li>Links to parent, siblings, children </li></ul></ul><ul><ul><li>Timers (time used, interval timer) </li></ul></ul><ul><ul><li>File system – Pointers to open files </li></ul></ul><ul><ul><li>Virtual memory assigned to this process </li></ul></ul><ul><ul><li>Processor-specific context </li></ul></ul>
    56. 57. Linux Process State
    57. 58. Linux Threads <ul><li>Threads are implemented as processes that share files, virtual memory, signals, etc. </li></ul><ul><ul><li>clone() system call to create a thread </li></ul></ul><ul><li>pthread library provides more user-friendly thread support </li></ul>