Chapter 3 process

  Modern process is time-sharing operating system work unit.

  Process is the basic unit of resource allocation.

  A thread is the smallest unit of program execution.

3.1 process concept

 

3.1.1 Process

  Process is the execution, which is an informal statement. Process not only the program code (also referred to as text sections), the process further comprising (a content value and processor registers program counter, etc.) data, the process stack (including temporary data, such as function arguments, local variables and return addresses) and data segments (including global variables) and heap. 

   Memory processes

 

 3.1.2 Process Status

  The new (new): the process of being created

  Run (running): command being executed

  Wait (waitting): process waiting to happen some time (such as I / O completion or receive signals)

  Ready (ready): the process is waiting dispatch processor

  Termination (terminated): execution process has been completed

 

 3.1.3 Process Control Block

  Each process in the operating system that the use of the process control block (Progress Control Block, PCB), also known as task control block. It contains information related to the process:

  • Process Status: new, ready, running, waiting, and stop;
  • Program Counter: Indicates the address of the next process to be executed one instruction;
  • CPU registers: includes an accumulator, index register, stack pointer, condition code, and other general-purpose registers information register. When an interrupt occurs, the program counter and status information with the need to save;
  • CPU scheduling information: a process priority, scheduling queue pointers and other scheduling parameters;
  • Memory management information: a base address and limit values ​​of registers, the page table or segment table;
  • Accounting information: including CPU time, the actual use of time, time period, accounting data, such as the number of jobs or processes;
  • I / O status information include: I / O device allocated to the process list and the like

3.1.4 Thread

  ...

3.2 Process Scheduling

  Target multi-channel programming is that whenever the process has run to maximize CPU utilization. The purpose time-sharing operating system is the CPU to quickly switch between processes, so that the user can interact with the program is running. To meet these objects, a scheduler selects an available process to execute on the CPU. Order Processing system does not have multiple processes running.

3.2.1 dispatch queue

  Process when entering the system, will be added to the job queue (job queue), the queue including all processes within the system.

  Resident in memory, ready and waiting to run the process is stored in the ready queue.

  Waiting for a particular I / O device called a device queue is a list of processes. Each device has its own device queue.

  Initially, the new process is added to the ready queue waiting, knowing that was selected to perform. When the process is executed assigned to the CPU, what time may occur:

  • Process may issue I / O requests, and placed into the I / O queue.
  • Process may create a child process and waits for its termination.
  • Process may be interrupted due to the forced release CPU, return to the ready queue

  The first two cases, the process will eventually switch from the wait state to the ready state, and put back into the ready queue. Repeat this process loop terminates know, then will be removed from all queues, PGB and its resources are released.

3.2.2 Scheduler

  The process will migrate between various scheduling queues, the operating system scheduler must wield a certain mode selection process from the queue. Select the appropriate process is performed by the scheduler or dispatcher.

  Typically, for a batch system, the process of submitting more than the process can be executed immediately, these processes will be saved to mass storage devices (usually disk) buffer pool for execution. Long-term scheduler from the pool that you select the program, added to memory for execution. Short-term scheduler or CPU scheduler selection process from the preparation process execution, and assign CPU.

  The main difference between the two is to perform frequency scheduling program.

    Short-term scheduling process must often choose new process for the CPU.

    Long-term scheduling process executed infrequently. Long-term scheduler controls the degree of multiprogramming (the amount of memory in the process). Long-term scheduler careful selection, should choose the right combination of process I / O-intensive and CPU-intensive.

  Some operating systems such as time-sharing operating system may introduce an additional medium-term scheduler. The idea is that the process can be swapped from memory swapped out.

3.2.3 context switching

  When an interrupt occurs, the system needs to save the context of the current processes running on the CPU so that recovery in the context of post-processing, which is to suspend the process, then the recovery process. PGB represented using process context.

  Switch the CPU to another process needs to save and restore the state of the current process to another process state, this task is called context switching.

3.3 processes running

  Most systems can process concurrently, they can be dynamically created and deleted, so the operating system must provide a mechanism to create a process and terminate the process.

3.3.1 Process Creation

  Process (parent process) can create multiple sub-processes in the implementation process, forming process tree.

  Most of the operating system for the identification process uses a unique process identifier pid, usually an integer.

  When the process of creating a new process, the parent process can be executed concurrently with the child; the child process the parent process to wait for some or all of the sub-processes executed.

Communication between processes 3.4

  Program concurrently executing operating system can be independent can also be a collaboration, to share data with other processes is a collaborative process. It allows a process to assist the reason: information sharing, speed up computing, modular and easy.

  Need help process communication mechanism between a process to allow the process of mutual exchange of data and information. Interprocess communication, there are two basic models: shared memory and message passing.

    Shared memory model will create an area of ​​memory for cooperating processes to share, this process provides a shared area to read or write data to exchange information.

    Message passing model provides for exchanging messages between collaborative process communication.

  Messaging data exchange less useful because no need to avoid conflict. For multi-core systems, message passing performance superior to the shared memory. Shared memory will cache coherency problem.

Guess you like

Origin www.cnblogs.com/astonc/p/12150702.html