Soft test--operating system knowledge--PV operation

Source: Internet
Author: User

1. There is a (D) relationship between any two concurrent processes.
A Individually completely independent B. have shared variable C. Must be mutually exclusive D. may be mutually restrictive
2. The relative speed at which the concurrent process executes is (D).
A B. Determined by the program structure of the process. C that is controlled by the process itself. The D that is determined when the process is created. Related to the process scheduling policy
3. A "time-related error" may occur when a concurrent process executes because of a concurrent process (A). A Use shared resource B. The order of execution C. The length of time required to calculate D. Length of the program
4. The program segments associated with shared variables in a concurrent process are called (B). A Shared sub-program B. Critical section C. Admin Area D. Public Data area
5. The PV operation used to implement the process synchronization and mutex is actually made up of the (D) process. A A can be interrupted by B. A non-disruptive C. Two can be interrupted D. Two non-interruptible
6. The process changes from a running state to a waiting state may be due to (B). A V Operation B was performed. P Operation C was performed. Time slices run out of D. High-priority processes are ready
7. When using PV operations to manage mutually exclusive resources, the initial value of the semaphore should be defined as (A). A Any positive integer B. 1 C. 0 D. -1
8. When using P and V operations to manage critical areas, the initial value of the mutex semaphore should be defined as (B).
A Any value B. 1 C. 0 D. -1

9. Existing n concurrent processes with a related critical section, if a process calls P operation and becomes waiting state, the value of the semaphore must be (A) when the p operation is called. A ≤0 B. 1 C. N-1 D. N
10. When using the PV operation to manage the critical zone, the initial value of the semaphore is defined as 1, there is a process in the critical section, but there are n processes waiting to enter the critical section, when the signal amount is (C). A -1 B. 1 C. -N D. N
11. When a wait process is awakened with a V operation, the state of the awakened process should become (B) state. A Execute B. Ready C. Run D. Resettlement
12. Inter-process synchronization refers to the logical mutual (B) relationship between processes. A Join B. Restricting
C Continue D. Call

1. The following description of the concurrency process, (CDE), is correct. A Allow multiple processes to run on the same CPU at any time B. The speed at which the process executes is controlled entirely by the process itself C. When a concurrent process accesses a shared resource, there may be time-related error D. Synchronization refers to the existence of a restrictive relationship in the concurrency process E. Independent concurrent processes do not interact with each other at execution time
2. After a running process calls P (s), the process can continue to run if the value of S is (AD). A S>0 B. s<0 C. S≠0 D. S≥0 E. S≤0

Judgment question
1. A concurrent process that has intercourse must share some resources. X
2. If you cannot control the relative speed of concurrent process execution, they must have time-related errors when they share resources. X
3. The execution result of the concurrent process depends only on the process itself and is unaffected by the outside world. X
4. The multi-channel program design inevitably leads to the concurrent execution of the process. √

There are m processes sharing the same critical resource, if the semaphore mechanism is used to achieve mutually exclusive access to the resource, then the change range of the semaphore value is _[1-m,1_]__.
For two concurrent processes, the mutex is set as mutex, and if mutex=0, then _b_
A indicates that no process has entered the critical section B indicates that a process has entered the critical section
c indicates that one process is entering the critical section and another process is waiting to enter
D means two processes are entering the critical section.
System has n (n>2) process, and is not currently executing the process scheduler, try to consider the following 4 cases which can not occur: A
A there is no running process, there are 2 ready processes, and the n-2 process is in a waiting state.
b There are 1 running processes, there is no ready process, the n-1 process is in a waiting form
C has 1 running processes, 1 ready processes, n-2 processes in wait state
D has 1 running processes, with n-1 ready process, no process in wait state

Application questions
Use P, v operation to achieve the following problems. There is a plate on the table that can store a fruit, and the father always puts an apple on the plate, and the mother always puts the banana on the plate; a son waits for a banana on the plate, while a female specializes in eating apples on the plate.
Set Dish=1 to indicate whether the plate is empty, apple=0 whether there is an apple on the plate, and banana=0 whether there are any bananas on the plate.

   semaphore dish=1;   semaphore apple=0;   semaphore banana=0;    Main()      {  cobegin             father();             mather();             son();             daughter();         coend         }
Father()                                                     {  while(ture)            {     p(dish);              将苹果放入盘中;              v(apple);          }      }
Mother()     {   while(ture)          p(dish);            将香蕉放入盘中;                v(banana);          }     }
son()      {  while(ture)          {     p(banana);          从盘中取出香蕉;                v(dish);               吃香蕉;          }      }
daughter()      {  while(ture)          {     p(apple);                从盘中取出苹果;                v(dish);               吃苹果;          }      }

A set of clothing factory has a two production room and a matching room. Two production rooms respectively produce tops and trousers, each made a coat or pants after the production room workers are to send them to the matching room hanger F1 and trouser rack F2, clothes rack F1 on the top, pants rack F2 storage pants, hangers can put up to 50 pieces of tops, trouser racks can put up to 50 pairs of trousers. The matching room The worker takes a coat and a pair of trousers from the frame, then sets them up and wraps them. In order to prevent the operation error, a production room workers and supporting room workers to the hanger F1 access action should be mutually exclusive, B production room workers and matching room workers to the trouser rack F2 access action should be mutually exclusive. The correct management of the P and V Primitives describes the working process of a production room worker, a B-studio worker, and a matching room worker.

Solution:
(1) Set common semaphore mutex1 and MUTEX2 control process mutually exclusive operation of hanger and trouser rack
Set the private semaphore empty1 and Empty2 respectively indicate the number of seats for hangers and trouser racks,
FULL1 indicates the number of clothes on the hanger, full2 the number of trousers on the trousers rack.
(2) Initialization of mutex1=1,mutex2=1,
Empty1=50,empty2=50,full1=0,full2=0
(3) Description:
A production room workers working process: B Production room workers working process:
L1: Produce a top L2: produce a pair of trousers
P (empty1) p (empty2)
P (MUTEX1) p (MUTEX2)
Put your blouse on the hanger and put your pants on the trouser rack.
V (mutex1) v (MUTEX2)
V (full1) v (full2)
Goto L1 Goto L2

Working process of the supporting workers:
L3:p (FULL1)
P (FULL2)
P (MUTEX1)
P (MUTEX2)
Matching tops and trousers separately
V (MUTEX1)
V (MUTEX2)
V (empty1)
V (Empty2)
Goto L3

In a box, mixed with equal numbers of black and white Weiqi. Now the use of automatic sorting system to separate sunspots, white children, set up a sorting system has two processes P1 and P2, wherein the process P1 pick the white son; process P2 pick sunspots. Rules each process to pick one son at a time, and when a process does not allow another process to pick, when a process picks one, it has to be picked up by another process. Try to write the program that the process P1 and P2 can execute correctly concurrently.
Set private semaphore s1=1;s2=0

P1 () {P2 () {
P (S1); P (S2);
Pick the white child; Pick sunspots;
V (S2);} V (S1);}

On the bus, the driver and the conductor's activities are respectively
Driver activity: Start the vehicle, normal operation, stop. Conductor activity: Closing, ticketing, opening. They are implemented using semaphores and P and v operations.

Set two semaphores: S1, S2,S1 Indicates whether the driver is allowed to start the car, the initial value of 0;S2 indicates whether the conductor is allowed to open the door, the initial value is 0.

      semaphore  s1=0;      semaphore  s2=0;      main( )     {         Cobegin          Driver( );          Busman();        Coend      } Driver()     {       While(true)       {   p(s1);          启动车辆;          正常行车;          到站停车;          V(S2);       }} Busman( ){  While(true)  {  关车门;V(S1); 售票;P(S2);开车门;上下乘客;}}

Soft test--operating system knowledge--PV operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.