02 computer operating system notes

Chapter 2 Process Management

2.1 The basic concept of the process

1. With regard to program execution order

1) prior to the introduction predecessor graph
described in FIG context processes executing
a directed acyclic graph (the DAG)
Pi node: a description block, process, or a statement.
Directed edge "->": between nodes or partial order relation preamble
Pi -> Pk, Pk is Pi is the immediate precursor chemotaxis, Pk is a direct successor of Pi.

2) executing a program sequence wherein

  • Sequential processor operating strictly according to a predetermined program execution sequence
  • Once closed the program started, the calculation results are not affected by external factors.
  • Reproducibility program execution as long as the initial conditions, regardless of the pause, how many times repeat the results are the same.

 

4) characteristic when the concurrent execution

  • Intermittent (running performance)
  • Lose closed
  • Results irreproducibility

 

2. Process

Definition 1) process

Process is the process of running the process entity, the system is an independent unit of resource allocation and scheduling.

Feature 2) process

  • --PCB fundamental structural characteristics, process
  • Dynamic process is essentially a process life cycle have an entity of the implementation process. Program is just a static set of ordered instructions. The most basic feature of the process
  • Concurrency of multiple processes with entities stored in the memory, running at the same time over a period of time. There are procedures to concurrent PCB.
  • Independence
  • Asynchrony

 

The basic state 3) process

  • Ready state (Ready) the process of obtaining all the necessary resources in addition to the CPU, the CPU Once the control can be run immediately.
  • Running state (Running) process has access to all resources necessary for the operation being performed on the processor.
  • After blocking state (Blocked) process is performed due to the occurrence of an event (request for I / O, application buffer, time slice to) while temporarily unable to perform, they give up the CPU to suspend

Three ground state of the conversion process (important)

 

3. The process control block PCB

1) Process control information (pcb within a block)

  • Process identifier information
  • Processor status information
  • Process scheduling information
  • Process Control Information

 

2) information is stored PCB

  • The system is running several programs have PCB, the PCB their permanent memory area.
  • Data structures used: PCB structure, PCB list or queue

3) PCB is organized

  • Link state same manner PCB, relying link pointer into the queue link. Ready queue; a plurality of blocking queue; empty queue (empty block PCB PCB area)
  • Indexing the same PCB with concentrated state record, but the record address index table PCB. Records of the index table with a special unit of the first address.

 

2.2 Process Control

The basic process control process:

  • Creation process
  • Termination process
  • Blocking the wake-up process
  • Suspend and activation process

1. Create a process

1) a process creates another process events (reasons)

2) creation process

(1) Blank application the PCB
(2) allocating resources for the new process
        is mainly handles memory resources
(3), the initialization process control block
        identifier (including the parent process), the program counter to the program entry address, the ready state and priority fill.
(4) the new process is inserted into the ready queue

 

2. terminate the process

1) termination of the process that caused the event

2) terminate the process

(1) According to the process identifier, the process retrieves the PCB, read its status.
    * IF execution state, the process is terminated immediately, scheduling flag is set to true, it indicates the re-scheduling.
    * IF there descendant process, should be terminated to avoid becoming uncontrollable process.
(2) to return all of the resources of its parent process or system.
(3) the PCB is removed from the process or where the queue list.

 

3. The process of blocking and wake

1) cause the process to block and wake-up event

2) blocking and wake-up process

(1) was changed to the blocking state of the PCB
(2) was added to the blocked queue PCB
(3) transfer process scheduling, the processor allocated to another process
(4) for process switching, i.e. switching PCB process according to the two protection and reset the processor status.

4. Suspend the activation process

(1) Check the state of the process is suspended, the active Ready to Ready stationary, the obstruction to the stationary blocking activity
(2) to copy the memory PCB (facilitate inspection) / external memory (swap) the designated area
(3 ) * If the process is suspended execution state, we need to re-process scheduling.

The implementation of the process of activating primitive
If the suspension process on the external memory, it is transferred to memory
check process status, if at a standstill ready, ready to active, if at a standstill blocked, instead blocking activity

 

 

2.3 Process Synchronization

Basic concepts of Process Synchronization

1) The main task synchronization process:

So that between the various processes efficiently executed concurrently share resources and cooperate with each other, so that the execution of the program having reproducibility.

2) Critical Resources

Allow only resources used by a process.

3) critical section

Access to critical resources of each process in the code that called the critical region.

For proper synchronization, critical section of code to increase control

4) the rules to be followed synchronization mechanism

  • Idle let into: basic principles of resource use
  • Busy waiting: to ensure mutual exclusion
  • Limited waiting: wake up when appropriate and so prevent dead
  • Let the right to wait: to take the initiative to prevent the release of CPU busy, etc.

 

 

2. semaphore mechanism

1) integer semaphore

The initial semaphore mechanism, two atomic operations to operate a shared integer quantity.

  • Signal is defined as the amount of an integer;
  • Assigned a value corresponding to the initial situation;
  • It can only be accessed via two atomic operations.
//p操作
wait(S):
    While S<=0 do no-op; 
    S:=S-1;

//v操作
signal(S):
    S:=S+1;

 

2) Record semaphore

Integer semaphore shortcomings

Integer semaphore in line with the principle of "limited waiting"

  • After the signal to release resources when the CPU is assigned to the waiting process, the process can still continue to wait, you can meet the "limited waiting."

But integer semaphore does not meet the "right to let the wait" principle

  • Integer semaphore wait operation, when s ≤0, the current process will continue to test CPU occupied;
  • Semaphore primitives can not be interrupted, this process occupies the CPU will always continue to occupy the CPU cycle continues into a busy and so on.

Improvement: conditions discrepancies should be able to give up the CPU

Not only have the value of the deal, as well as the processing queue.
At this time, the data recording type structure is formed, comprising two parts:

  • Integer variable value (representing the number of resources)
  • Process list L (links to all wait for the process)

Code Description:
type = Record Semaphore
    value: Integer;
    L: List of the PCB;
End;
operation: S.Value, SL

Value> 0, represents the number of currently available resources;
Value≤0, which represents the absolute value of the number of processes waiting to use the resource, i.e. the number of queued in the queue of this semaphore PCB.

Not only modify the number of resources, but also to block the process of handling, wake-up and other operations. To modify the number of resources, re-determination process.

//P操作
wait():
    S.value = S.value - 1;
    if  S.value < 0  then  block(S,L)

//v操作
signal():
    S.value = S.value + 1;
    if  S.value <= 0 then wakeup(S,L)

 

3) AND semaphore

  • The reason: Some applications often require two or more shared resources, rather than a resource foregoing. The more the process also requires shared resources, the greater the possibility of a deadlock occurs.
  • Solving ideas: a one-time allocation of resources required to process, release runs together. Wait operation all the resources it needs to be judged, there is an AND condition, it said "AND Sync", "At the same wait".

4) Set a semaphore

Introducing reasons:

  • You can only get a unit or release resources, inefficient;
  • Sometimes there is a lower limit of resource allocation limit;
  • Review: The premise of low value t is larger than the set can be assigned, it can be assigned each time a d.

 

 

 

2.4 classical process synchronization problem

1, the producer - consumer issues mutually exclusive, synchronized

2, exclusive dining philosophers problem

3, the reader - to write the problem of conditional mutually exclusive

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Wjwstruggle/article/details/82861121