[Operating system] process management concept

Execution of the program

  • Order execution
    • Sequential
    • Closed
    • Renewable
  • Concurrent execution
    • Intermittent
    • Lose closed
    • Non-renewable

process

  • Five feature
    • dynamic
    • Complicated by
    • independent
    • asynchronous
    • Structured
  • Static description
    • Process Block = PCB + + Data collection
  • The basic state
    • New - meet all the conditions except for CPU -> Ready - made CPU-> Run -> End
    • Run - an event occurs while waiting for sleep -> waiting - waiting for the incident and awakened -> Ready
    • Run - break -> Ready
  • The difference between the process and procedures:

Process is dynamic and static procedures.

  • Parallel and concurrent difference
    • parallel
      • The same time, the two transactions are active
      • For example, in the super-pipelined CPU design, superscalar design
    • Complicated by
      • Macro executed in parallel, order of execution microscopic
      • Only one thing at a time is active
      • For example, time-sharing operating system to run multiple programs at the same time

 

Composition 1 process

  •  Text segment (code segment): comprising program code
  • Stack segments: include temporary data, such as function parameters, return address, local variables
  • Stack: a running process comprising dynamically allocated memory segment, such as a user's pointer malloc
  • Data segments: including global variables

 

State transition diagram 2 processes

Status Features 1) process:

  • Run: The instruction is being executed
  • Wait / blocked: running processes due to the occurrence of an event temporarily unable to go into the execution (such as waiting for the completion of the IO)
  • Ready: Process all assigned resources except for CPU status
  • Termination: complete the implementation process
  • New: The process is being created
  • Pending: artificially processes running process or not running pauses to its research / modification

 

2) Process State Transition

  • Ready -> Run
    • Scheduler to select a new process to run
  • Run -> Ready
    • Running processes run out of time slice
    • Running process is interrupted, because a high-priority process in the ready state
  • Run -> wait
    • OS unfinished tasks
    • Access to a resource is still unable to carry out
    • IO initialization and must wait for the results
    • Wait for a process to provide input (IPC)
  • Wait -> Ready
    • When the process was assigned to all resources except for CPU resources

 

3-process communication

  • Synchronization process - the low level communication
    • Competition for resources
      • Critical section
        • Mutual exclusion --------- |
    • Mutual cooperation |
      • Synchronization ---------------------> semaphore mechanism
  • Advanced Communications
    • Shared memory system
      • Based on shared memory mode
    • Information delivery system
      • Direct communication
        • Master-Slave
        • Conversational
        • Message Buffer
      • Indirect communication
        • mailbox

Definition: exchange of information between concurrent processes is called interprocess communication. The exchange of information is at least one state or value, as many as tens of thousands of bytes

  • Shared memory
    • Information transfer between processes achieved through shared variables.
  • Messaging
    • The exchange of information between processes in the message as a unit, a set of communication directly programmer system-provided commands (Send message transmitting and receiving primitive Receive primitive information) to communicate the messaging system may be divided into a communication message buffer and mail communication.

Shared memory is faster than messaging!

 

 

4 CPU scheduling (scheduling process) big issue / Short Answer

Scheduling Algorithm

Calculation Rules

Remark

First-come, first-served FCFS

Only consider the waiting time for each job

Disadvantages:

  • Turnaround time and response time can not be guaranteed
  • Adverse short work

Short operating priority SJF

Only consider the execution time of each job

  • Divided preemptive and non-preemptive. Non-preemptive known as "shortest remaining time priority"
  • Requires prior estimated that each job of processor time
  • There is a long job is like to starve to death
  • Favor short job, is not conducive to sharing system (due to the non-preemption)

The highest ratio corresponding HRF

Ratio corresponding to R = 1 + W / T = 1 + a job waiting time / job estimated time to run (i.e., the service time requirement)

  • The average turnaround time and average turnaround time with full view, HRP between SJP and FCFS, better than FCFS, inferior SJP

RR Round Robin

Waiting time and execution time proportional to the length of the time slice selected value q

  • Based on preemption clock
  • Minute time slot on the need to first process arranged in accordance with the arrival time of a queue, process scheduler always selects the first process ready queue of execution, but only run a time slice, put him to return to the ready queue at the end of the qwq
  • Quantum size great influence on the performance of the RR. Decision time T with the process ready queue and the number n of quantum size, typically in response by the system. Q is proportional to the time slice the list T, is inversely proportional to n, i.e., q = T * n
  • In fact, q is also related to the cpu speed. cu running speed may be smaller if q w

Multilevel Feedback Round Robin

Divided into different queues given different priority and time slice

  • Is a round-robin scheduling and priority scheduling algorithm integrated development results w

Priority of law

Divided into static priority, dynamic priority

There is a low priority starve to death is like - Solution: aging, that is, over time, increase the priority of w

Performance metrics: turnaround time, with the right turnaround time, response time

 

5 Process Synchronization 30 points big questions + short answer

 

  • Critical resources:
    • Multiple processes share a resource
    • Only one process at any time using the resource
  • Critical section:
    • Some piece of code may be modified to a shared data
    • feature
      • When a process executing a critical section, no other process can not re-enter the critical section execution
      • Multiple processes competing to enter the same critical region, they are "mutually exclusive" relationship.
    • Three Requirements
      • The most basic: exclusive
      • Forward: let into idle
      • Finite Waiting: To control the process from the request made to enter the critical section to process the request is allowed, the number of other processes are allowed to enter the critical section (to avoid the process of waiting too long)

 

  • Exclusive
    • A set of one or more blocks of concurrent processes, because they share a common resource results in the unit must be performed in order to perform a cross is not allowed.
  • Semaphore mechanism to resolve synchronization, mutual exclusion problem
    • signal
      • The physical meaning: S> 0 indicates there are resources available S, S = 0 indicates no resources are available, s <0, the absolute value of s represents the number of wait queue process
    • PV operation
      • p: wait (S) primitives, when found in S <= 0 must block their own time
      • V: signal (S) primitives, when a process blocked and waiting when the semaphore S can be re-executed after other processes signal operation
      • Generally, the process requires the implementation of B after A is only required to operate in a pre-B-P, beginning with the V operation on a semaphore with the end of A
  • Producer - consumer model

Problem Description: A group of producer processes and consumer processes share a set of initial size is empty, a buffer of size n; buffer happy when the news producers to visit Japan buffer; otherwise it must wait. Only when the buffer is not empty, consumers can extract information from, or else must wait. Since the buffer is a critical resource, so it only allows a producer into information, or removed from a consumer information.

  • Single consumer producer
    • 1 1 producer of consumers, buffer size n case

Semaphore mutex = 1 // mutex critical area for PV applied to both sides of the critical zone is operated

Semaphore empty = n; // free buffer

Semaphore full = 0 // initialized to empty the buffer

Producer()

{

While(1)

{

Produce an item in nextp;

P(empty);

P (mutex); // clamping mutex

Add item to buffer

V(mutex);

V(full);

}

}

Customer()

{

While(1)

{

P(full)

P(mutex)

remove an item from buffer

V(mutex)

V(empty)

Consume the item

}

}

  • 1 1 1 Consumer producers do not have the buffer mutex

Producer()

{

While(1)

{

Produce an item

P(empty)

Add item to buffer

V(full)

}

}

Customer()

{

While(1)

{

P(full)

Remove an item from buffer

V(empty)

Comsume the item

}

}

  • 1 producers and more consumers
    • Producers such as 1 3 1 Consumer buffer (multi-buffer to add mutex)

S1 = S2 = S3 = 0,S = 3

P1:

Begin

P(S)

P(S)

P(S)

 Message buffer to buffer

V (S1)

V(S2)

V (S3)

End

P2:

Begin

P(S1)

Read the message

V(S)

End

P3:

Begin

P(S2)

Read the message

V(S)

End

P4:

Begin

P (S3)

Read the message

V(S)

End

 

 

  • Dining philosophers problem

ABCD philosophers together to discuss issues, they discussed the gap meal. No one fork to each one, but put a set of cutlery reference only sit between two people. Please use semaphores PV description of the synchronization, mutually exclusive relationship thinking philosopher.

solution:

Provided semaphores S1, S2, S3, S4 initial values ​​are 1

Procedurei(I = 1,2,3):

P (Si);

P (Si + 1);

Eating;

The (Si);

The (Si + 1)

 

Procedure4:

P (S4);

P(S1);

Eating;

V (S4);

V (S1);

6 Deadlock

  • Cause of a deadlock
    • Competition for resources
    • Improper order to promote the process
  • Four necessary conditions for deadlock (to break a deadlock on destroyed)
    • Mutually exclusive: Only one process may use a resource
    • Not seize: Resources process can only be obtained after the release of their own after the completion of use
    • Possession and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes
    • Circular wait: there is a process to wait for resources between the ring
  • Deadlock
    • Deadlock Prevention

It is more difficult to destroy mutually exclusive and can not be preempted, it is generally by order of the static resource allocation / resource allocation, that is, possession of break and wait or wait for the cycle to prevent deadlock

  • Destruction of the loop condition (ie, circular wait condition): Resource orderly distribution method
  • Destruction request and maintenance conditions: one-time resource allocation
  • Be deprived of resources: the destruction can not be preempted resource conditions
  • Avoid deadlock

To take measures to prevent the system from entering implemented according to an unsafe condition.

  • Bankers algorithm: the operating system within the rules established by the bankers to allocate resources for the process, it can keep the system in a safe state. But he must be calculated before each assignment, time-consuming, the system is a big overhead
    • Pre-allocation algorithm
    • Security Detection Algorithm
  • Deadlock Detection
    • 1 in the process - to find a process node P1 resource figure, P1 side can request immediate gratification. P1 find the words to put even the edges are deleted, then returns to the operation until the end of simplification.
    • If the map S is deadlock, the process of S if and only if the resource figure is not entirely Simplification
  • Deadlock lift
    • Revocation process
      • Forced to withdraw some or all of the process deadlock and deprive them of resources
    • Deprived of resources
      • Suspend certain thought processes, and seize his resources, these resources will be allocated to other process deadlock

 

Guess you like

Origin blog.csdn.net/sinat_39763590/article/details/93157098