Files
uni/year2/semester1/logseq-stuff/pages/Process Management.md

21 KiB

  • #CT213 - Computer Systems & Organisation
  • Previous Topic: System Software & Operating Systems
  • Next Topic: CPU Management - Scheduling
  • Relevant Slides: Lecture 4.pdf
  • Programs & Processes

    • What is a Program? #card card-last-interval:: 4 card-repeats:: 2 card-ease-factor:: 2.32 card-next-schedule:: 2022-11-26T13:37:45.329Z card-last-reviewed:: 2022-11-22T13:37:45.329Z card-last-score:: 3
      • A Program is a static entity made up of source program language statements that define process behaviour when executed on a set of data.
    • What is a Process? #card collapsed:: true card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.6 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T16:39:13.229Z card-last-score:: 1
      • A Process is a dynamic entity that executes a program on a particular set of data using resources allocated by the system.
        • Two or more processes could execute the same program, each using its own data & resources.
      • It is a ^^program in execution.^^
      • It is composed of:
        • Program.
        • Data.
        • Process Control Block (PCB): contains the state of the process in execution.
    • Process Execution #card

      collapsed:: true card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T20:14:34.752Z card-last-score:: 1
      • In order to execute, a process needs an Abstract Machine Environment to manage its use of resources.
      • The Process Control Block (PCB) is required to map the environment state onto the physical machine state.
      • The OS keeps a process descriptor for each process.
      • image.png
    • Program Execution #card

      collapsed:: true card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.6 card-next-schedule:: 2022-11-22T00:00:00.000Z card-last-reviewed:: 2022-11-21T13:09:10.088Z card-last-score:: 1
      • Each execution of a program generates a process that is executed.
      • Inter-process relationships:
        • Competition: Processes are trying to get access to the same resources of the system, therefore a protection between processes is necessary.
        • Cooperation: Sometimes the processes need to communicate between themselves and exchange information - synchronisation is needed.
    • Process Manager #card

      card-last-score:: 1 card-repeats:: 1 card-next-schedule:: 2022-11-18T00:00:00.000Z card-last-interval:: -1 card-ease-factor:: 2.5 card-last-reviewed:: 2022-11-17T20:18:15.885Z
      • What does the Process Manager do? #card card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T20:13:51.555Z card-last-score:: 1
        • The Process Manager implements:
          • CPU Sharing (called scheduling): Allocate resources to processes in conformance with certain policies.
          • Process Synchronisation & Inter-Process Communication: Deadlock strategies & protection mechanisms.
        • image.png
    • Process - User Perspective

      • When processes are executed in a quasi-parallel fashion, the processes need to synchronise to each other for correct functionality - this is done with directives wait/signal.
        • wait- wait for a signal from a specific process.
        • signal - send a signal to a specific process.
    • Process - OS Perspective #card

      collapsed:: true card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-24T00:00:00.000Z card-last-reviewed:: 2022-11-23T12:20:00.645Z card-last-score:: 1
      • The processor's principle function is to execute machine instruction residing in main memory.
        • These instructions are provided in the form of programs.
        • A processor may interleave the execution of a number of programs over time.
      • Program View

        • Its execution involves a sequence of instructions within that progam.
        • The behaviour of individual processes can be characterised by a sequence of instructions called the trace of the process.
      • Processor View

        • The processor executes instructions from main memory, as dictated by changing values in the Program Counter (PC) register.
        • The behaviour of the processor can be characterised by showing how the traces of various processes are interleaved.
    • State Process Models

      • Two-State Process Model #card

        card-last-interval:: 15.48 card-repeats:: 4 card-ease-factor:: 2.08 card-next-schedule:: 2022-11-30T07:19:45.198Z card-last-reviewed:: 2022-11-14T20:19:45.199Z card-last-score:: 3
        • The process can be in one of two states: running or not running.
        • When the OS creates a new process, it enters into the not running state; after that, the process exists - it 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 new process will be moved to the running state and the former one to the not running state.
        • Two-State Model Queuing Discipline #card

          card-last-interval:: 1.01 card-repeats:: 2 card-ease-factor:: 2.36 card-next-schedule:: 2022-11-15T20:13:25.916Z card-last-reviewed:: 2022-11-14T20:13:25.916Z card-last-score:: 3
          • Each process needs to be represented.
            • Information relating to each process, including current state & location in memory.
            • Waiting processes should be kept in some kind of queue.
              • List of pointers to processes blocks.
              • Linked list of data blocks, each block representing a process.
          • Dispatcher behaviour:
            • An interrupted process is transferred to the waiting queue.
              • If the process is completed or aborted, it is discarded.
            • The dispatcher selects a process from the queue to execute.
      • Five-State Process Model #card

        card-last-interval:: 4 card-repeats:: 2 card-ease-factor:: 2.22 card-next-schedule:: 2022-11-18T16:27:46.160Z card-last-reviewed:: 2022-11-14T16:27:46.161Z card-last-score:: 3
        • Running: The process is currently being executed.
          • For single-processor systems, one single process can be in this state at a time.
        • Ready: The process is prepared to execute when given the turn.
        • Blocked: The process cannot execute until some event occurs.
          • Such as the completion of an I/O operation.
        • New: The process has been created, but has not yet been accepted in the pool of executable processes by the OS.
          • Typically, a new process has not yet been loaded into main memory.
        • Exit: The process has been released from the pool of executable processes by the OS.
          • Completed or due to some errors.
        • Five-State Model Process Transition Diagram

          • image.png
          • Five-State Model Queuing Discipline #card

            collapsed:: true card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-18T00:00:00.000Z card-last-reviewed:: 2022-11-17T20:18:38.089Z card-last-score:: 1
            • There are two types of queues: the ready queue & the blocked queue.
              • When a process is admitted into the system, it is placed in the ready queue.
              • When a process is removed from the processor, it is either placed in the ready queue or the blocked queue, depending on the circumstances.
              • When an event occurs, all the processes waiting on that event are moved from the blocked queue into the ready queue.
              • image.png
            • There are multiple blocked queues - one per event.
              • When the event occurs, the entire list of processes is moved to the ready queue.
              • image.png
          • Suspended Processes #card

            card-last-interval:: 0.79 card-repeats:: 2 card-ease-factor:: 2.36 card-next-schedule:: 2022-11-15T10:27:13.430Z card-last-reviewed:: 2022-11-14T16:27:13.430Z card-last-score:: 3
            • The processor is faster than I/O so all the processes could be waiting for I/O.
            • You can swap these processes to the disk to free up some memory.
            • The blocked state becomes the suspended state when swapped to the disk.
            • image.png
    • Process Creation #card

      card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-19T00:00:00.000Z card-last-reviewed:: 2022-11-18T18:35:10.727Z card-last-score:: 1
      • Creation of new processes:
        • The OS builds the data structures that are used to manage the process.
        • The OS allocates space in main memory to the process.
      • Reasons for process creation:
        • New batch job.
        • Interactive logon.
        • Created by OS to provide a service.
          • i.e., process to control printing.
        • Spawned by existing process.
          • i.e., to exploit parallelism.
    • Process Termination

      card-last-score:: 1 card-repeats:: 1 card-next-schedule:: 2022-10-08T23:00:00.000Z card-last-interval:: -1 card-ease-factor:: 2.6 card-last-reviewed:: 2022-10-08T15:27:20.789Z
      • Reasons for Process Termination: #card card-last-interval:: 8.88 card-repeats:: 3 card-ease-factor:: 2.22 card-next-schedule:: 2022-11-23T13:37:45.614Z card-last-reviewed:: 2022-11-14T16:37:45.615Z card-last-score:: 3
        • Process finished its execution (natural completion).
        • Total time limit exceeded.
        • Errors (memory unavailable, arithmetic error, protection error, invalid instruction, privileged instruction, I/O failure, etc.).
    • Process Management Services #card

      collapsed:: true card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.7 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T16:43:04.324Z card-last-score:: 1
      • create(&process_id, attributes)
        • Creates a new process with implicit or specified attributes.
      • delete(process_id)
        • Sometimes known as destroy, terminate, or exit.
        • Ends the process specified by process_id.
        • Whenever the process is terminated, all the files are closed, and all the allocated resources are released.
      • abort(process_id)
        • The same as delete but for abnormal termination.
        • Usually generates a "post-mortem dump" which contains the state of the process before the abnormal termination.
      • suspend(process_id)
        • Puts the specified process into a suspended state.
      • resume(process_id)
        • Moves the specified process from the suspended state to the ready state.
      • delay(process_id, time)
        • Suspends the specified process for a specified period of time.
        • After the delay time elapses, the process is moved to the ready state.
      • get_attribtutes(process_id, &buffer_attributes)
        • Used to find out the attributes for the given process.
      • set_attributes(process_id, buffer_attributes)
        • Used to set the attributes of the specified process.
    • Process Description

      • OS Control Structures #card

        card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T16:26:10.635Z card-last-score:: 1
        • Memory Tables #card

          card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.36 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T16:26:25.598Z card-last-score:: 1 collapsed:: true
          • Memory Tables are used to keep track of both main (real) and secondary (virtual) memory. collapsed:: true
            • Some of the main memory is reserved for use by the OS, the remainder is available to the processes.
          • Memory Tables contain:
            • The allocation of main memory to processes.
            • The allocation of secondary memory to processes.
            • Any protection attributes of blocks of main or virtual memory (such as which processes can access certain shared memory regions).
            • Any information needed to manage virtual memory.
        • I/O Tables #card

          card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-19T00:00:00.000Z card-last-reviewed:: 2022-11-18T18:35:16.384Z card-last-score:: 1 collapsed:: true
          • I/O Tables are used by the OS to manage the I/O devices.
            • At any given time, an I/O device may be available or assigned to a particular process.
            • If an I/O operation 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.
        • File Tables #card

          card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.36 card-next-schedule:: 2022-11-18T00:00:00.000Z card-last-reviewed:: 2022-11-17T19:40:13.935Z card-last-score:: 1 collapsed:: true
          • File Tables provide information about:
            • The existence of files.
            • Their location in secondary memory.
            • Their current status.
            • Other attributes.
          • Much of this information is maintained & managed by the File Manager, in which case the process manager has little or no knowledge of files.
        • Process Tables

          card-last-score:: 1 card-repeats:: 1 card-next-schedule:: 2022-10-07T23:00:00.000Z card-last-interval:: -1 card-ease-factor:: 2.5 card-last-reviewed:: 2022-10-07T10:23:42.819Z collapsed:: true
          • What is the Primary Process Table? #card card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.36 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T16:26:29.312Z card-last-score:: 1
            • The Primary Process Table keeps one entry per each process in the operating system.
              • Each entry contains at least one pointer to a process image.
        • Process Image #card

          card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T16:26:31.530Z card-last-score:: 1 collapsed:: true
          • The Process Image contains:
            • Stack collapsed:: true
              • Each process has one or more stack(s) associated with it.
              • A stack is used to store parameters & calling addresses for procedure & system calls.
            • User Data collapsed:: true
              • Program data that can be modified, etc.
            • Process Control Block #card card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-23T00:00:00.000Z card-last-reviewed:: 2022-11-22T13:37:47.650Z card-last-score:: 1 collapsed:: true
              • Data needed by the OS to control the process (attributes & information about the process).
              • Contains:
                • Process Identification: The data always includes a unique identifier for the process.
                  • Numeric identifiers that may be stored with the Process Control Block include the identifier of this process, the identifier of the process that created this process (parent process), and the User Identifier.
                • Processor State Information: Defines the status of a process when it is suspended.
                  • User-Visible Registers card-last-score:: 1 card-repeats:: 1 card-next-schedule:: 2022-10-08T23:00:00.000Z card-last-interval:: -1 card-ease-factor:: 2.5 card-last-reviewed:: 2022-10-08T15:22:36.520Z
                    • What is a User-Visible Register? #card card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-18T00:00:00.000Z card-last-reviewed:: 2022-11-17T09:49:41.863Z card-last-score:: 1
                      • A user-visible register is one that may be referenced by means of the machine language that the processor executes.
                  • Control & Status Registers #card card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-22T00:00:00.000Z card-last-reviewed:: 2022-11-21T13:08:22.338Z card-last-score:: 1
                    • These are a variety of processor registers that are employed to control the operation of the processor. These include:
                      • Program Counter: Contains the address of the next instruction to be fetched.
                      • Condition Codes: Result of the most recent arithmetic or logical operation.
                      • Status Information: Includes interrupt enabled/disabled flags, execution mode.
                  • Stack Pointers
                    • Each process has one or more LIFO system stacks associated with it. A stack is used to store parameters & calling addresses for procedure & system calls.
                      • The stack pointer points to the top of the stack.
                • Processor Control Information: Used by the OS to manage the process.
                  • Scheduling & State Information #card card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.5 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T16:26:18.371Z card-last-score:: 1
                    • This is information that is needed by the operating system to perform its scheduling function. Typical items of information include:
                      • Process State: Defines the readiness of the process to be scheduled for execution (e.g., running, ready, waiting, halted).
                      • 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).
                      • Scheduling-Related Information: This will depend on the scheduling algorithm used. Examples are the amount of time that the process has been waiting an the amount of time that the process executed the last time it was running.
                      • Event: Identity of the even the process is awaiting before it can be resumed.
                      • Data Structuring: A process may be linked to another process in a queue or other structure.
                      • Inter-Process Communication: Various flags, signals, & messages may be associated with communication between two independent processes.
                      • Process Privileges: Processes are granted privileges in terms of the memory that may be accessed and the types of instruction that may be executed. In addition, privileges may apply to the use of system utilities & services.
                      • Memory Management: This section may include pointers to segment and/or page tables that describe the virtual memory assigned to this process.
                      • Resource Ownership & Utilisation: resources controlled by the processes may be indicated, such as opened files. A history of utilisation of the processor or other resources may also be included.
                        • This information may be needed by the scheduler.
  • Threads & Processes

    • A process is sometimes defined as a heavyweight process.
    • A thread is defined as a lightweight process.
    • Separate two ideas:
      • Process: Ownership of memory, files, other resources.
        • Execution of applications.
      • Thread: Unit of execution we use to dispatch.
        • Share the same address space hence we can read from and write to the same data structures.
    • What is multithreading? #card card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.46 card-next-schedule:: 2022-11-18T00:00:00.000Z card-last-reviewed:: 2022-11-17T20:15:51.123Z card-last-score:: 1
      • Multithreading allows multiple threads per process.
    • What is a thread? #card card-last-interval:: -1 card-repeats:: 1 card-ease-factor:: 2.7 card-next-schedule:: 2022-11-15T00:00:00.000Z card-last-reviewed:: 2022-11-14T16:35:09.592Z card-last-score:: 1
      • A thread is a unit of computation associated with a particular heavyweight process, using many of the associated process's resources.
        • It has a minimum of internal state & a minimum of allocated resources.
      • A group of threads are share the same resources.
        • e.g., files, memory space, etc.
      • The process is the execution environment for a family of threads.
        • A process with one thread is a classic process.
      • Each thread has an individual execution state.
      • Each thread has a control block, with a state (Running / Blocked / etc.), saved registers, an instruction pointer.
      • There is a separate stack & hardware state (PC, registers, PSW, etc.) per thread.
      • Shares memory & files with other threads that are in that process.
      • Faster to create a thread than a process.
      • image.png