Soft test senior system architect designer (3) operating system 1 process of basic knowledge

Table of contents

overview

 Operating System Overview

​edit

process management

state of the process

 Process management-PV operation

Use PV operation to realize process synchronization

 Process Management - Predecessor Diagram

 Process Management - Deadlock


overview

 Operating System Overview

Functions of the operating system: process management, storage management, file management, job management, device management

operating system characteristics

  • concurrency
  • sharing
  • Virtuality
  • Uncertainty

 

process management

  1. A process is a process in which a program runs on a data set, and it is an independent unit for resource allocation and scheduling by the system
  2. The composition of the process
  • Process control block PCB (unique logo)
  • Program: Describes what the process is going to do
  • Data: store the data required for the execution of the process

  

     3. The difference between a process and a program:

  • A process is an execution process of a program, there is no process without a program
  • A program is a collection of a series of program statements to complete a specific function, as long as it is not destroyed, it will exist forever
  • A program is a static concept, while a process is a dynamic concept, which is produced by creation and dies due to cancellation after completing the task
  • A process is an independent unit for resource allocation and scheduling by the system, while a program is not 

Processes and threads:

Two basic properties of a process:

1) An independent unit that can own resources;

2) The basic unit that can independently schedule and allocate resources;

ps: Threads can only be scheduled independently and do not allocate resources

 

Threads do not share: program counter, stack, registers 

PCB

 

PCB organization method: linear method, link method, index method

state of the process

Three-state diagram:

                   run ready block

CPU           YES       NO       NO

非CPU        YES       YES     NO

Blocking: Cannot go directly to "run"

 Five state diagram:

 Hang: program scheduling, exceptions, etc.

"Active and ready": Only this state can go to "Run"

"Active Blocking": You have to go through "Static Blocking", "Static Ready" and "Active Ready" before you can go to "Run".

 Process management-PV operation

Semaphore mechanism

In 1965, the semaphore mechanism proposed by Dutch scholar Dijkstra is an effective tool for process synchronization and mutual exclusion .

The semaphore is an integer variable, which can be assigned different values ​​according to different control objects.

PV operation is a common method to realize process synchronization and mutual exclusion. Process synchronization and mutual exclusion are the prerequisites for learning PV operations.

Synchronization and mutual exclusion tend to coexist in real problems, not antonyms.

The opposite of synchronous is asynchronous .

The antonym of mutual exclusion is sharing .

Mutual exclusion: A certain resource (that is, critical resources, such as printers, buffers, and process indirect constraints) can only be used by one task at the same time . It needs to be locked when used, and can be used by other tasks after being unlocked after use;

Synchronization: Multiple tasks can be executed concurrently, but there is a difference in speed. Under certain circumstances, they stop and wait , and there is no question of whether resources are separate or shared; such as bicycles and cars. Process Direct Constraints

P operation : [ apply for resources , S=S-1], if S>=0, the process that executes P operation will continue to execute; if S<0, it means insufficient resources, go to queue, then set the process to a blocked state (because No resources available), and insert it into the blocking queue.

V operation : [ Release resources , S=S+1], if S>0, the process executing V operation continues; It is inserted into the ready queue (at this time, the process blocked by the P operation due to lack of resources can continue to execute), and then the process executing the v operation continues.

 Note: A critical section is a piece of code;

S represents the resource situation and the number of processes waiting for a negative value. S=S-1 means to apply for resources; S=S+1 means to release resources

Mutual exclusion semaphore: use mutual exclusion access to critical resources. After using the mutual exclusion semaphore, other processes cannot access it. The initial value is 1 .

Synchronous semaphore: access control to shared resources, the initial value is generally the number of shared resources .

Use PV operation to realize process synchronization

Process synchronization is a mutual restriction problem caused by inter-process cooperation . To achieve process synchronization, a semaphore can be used to link messages.

A classic example of a synchronization problem is the producer-consumer problem.

 

 Practice questions:

 Process Management - Predecessor Diagram

 ps: dependencies. Only when A, B, and C are completed, can D be started. D is completed before starting E.

PS: V for pre-action, P for post-check

Practice questions:

 

 Practice questions:

 ps: The direct constraint relationship is the influence of sequence

Practice questions:

 Process Management - Deadlock

Deadlock: When a process waits for something that cannot happen, the process is deadlocked.

4 necessary conditions for deadlock:

Mutual exclusion condition: The process uses the allocated resource exclusively, that is, a resource can only be occupied by one process within a period of time, and other processes requesting the resource wait until the resource is released.

Request and hold conditions: When a process blocks and waits for a request for resources, it keeps holding on to the resources it has acquired.

Non-preemptive (deprivation) conditions: The resources that the process has acquired cannot be forcibly deprived before they are used up.

Circular waiting condition: A circular waiting resource relationship is formed between several processes.
 

 

Practice questions:

 S < 5: Definitely deadlock

If A, B, and C each have 4 resources, and one more resource is given, there will be no deadlock. so:

S= [5,12] may be deadlocked, may not be deadlocked

s>13, there will be no deadlock.

If there are m processes, all need n resources,

Then deadlock is impossible: S > m *(n-1) + 1

Guess you like

Origin blog.csdn.net/wodeyijia911/article/details/131293750