Operating System Principles and Linux Practice Course Exercise 2

Chapter two

The following are all personal homework, please point out any mistakes, thank you

2-2
Answer: It is impossible for the process to run uninterrupted, because there are system function call handlers, clock interrupt handlers, and system function call handlers in the operating system, which will cause interruptions.
insert image description here

2-3
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

2-5 The arrival time of the 4 jobs in the multi-programming system and the estimated running time are shown in the following table:
insert image description here
(1) The system uses the SJF algorithm to schedule processes, with no limit on the number of processes, and calculates the average turnaround time and average weighted turnaround time of jobs Time;
(2) The system uses the SJF algorithm to schedule jobs, uses the SRTF algorithm to schedule processes, limits the number of processes to no more than 2, and calculates the average turnaround time and average weighted turnaround time of jobs.

insert image description here

2-6. The multi-programming system currently has 100KB of memory, 2 tape drives, and 1 printer for user processes to use. It adopts variable partition memory management and adopts static allocation method for devices, that is, obtains all required device resources before the process runs. User job I/O operation time is ignored. The existing job sequence is shown in the following table:
insert image description here
FCFS strategy is used to schedule jobs. If the arrival time is the same, the jobs will be started in the order in which the resources are obtained. The low memory address area will be allocated first, and the memory jobs cannot be moved. Find: (1) The sequence of job
scheduling sequence;
(2) start and end time of each job;
(3) average turnaround time and average weighted turnaround time of jobs.

analyze:

  • 8:00 Job1 arrives at the system and starts to execute. It allocates memory and resources in the low address area. The running time is 25 minutes. After resources are allocated, the remaining 1 is for the tape drive and 0 for the printer.
  • 8:20 job2 and job3 arrive at the system at the same time, because there is 1 left in the tape drive and 0 left in the printer at this moment, so job2 enters the waiting state. There are 60KB free blocks, after allocating memory and resources for job3, the remaining 0 for the tape drive and 0 for the printer
  • 8:25 Job1 is executed and the resources are released. At this moment, there are 1 left in the tape drive and 1 left in the printer. job3 starts executing. Because there is no free memory block of 30KB, job2 is still waiting.
  • 8:30 job4 arrives at the system, and there are 20KB free blocks, so memory and resources are allocated for job4. After the allocation, the remaining 0 for the tape drive and 1 for the printer
  • 8:35 job5 arrives at the system, because there is no tape drive, so it enters waiting
  • 8:45 The execution of job3 is completed, and the memory and resources are released. At this moment, 1 tape drive and 1 printer remain. There are 30KB free blocks, allocate memory and resources for job2, after allocating resources, there is 1 left for the tape drive, 0 left for the printer, and job2 starts to execute. Because there is no printer, job5 continues to wait
  • 8:55 Job2 is executed and resources are released. At this moment, 1 tape drive and 1 printer remain. job4 starts executing. There are 10KB free blocks to allocate memory and resources for job5. After allocating resources, 0 is left for the tape drive and 0 is left for the printer.
  • 9:15 The execution of job4 is completed and resources are released. At this moment, the tape drive has 1 remaining, and the printer has 0 remaining. job4 starts execution
  • 9:30 The execution of job5 is completed and resources are released. At this moment, there are 2 tape drives and 1 printer left.
    insert image description here

Solution:
(1)
insert image description here
The sequence of job scheduling is: Job1, Job3, Job2, Job4, Job5.

(2) The start and end times of each job are shown in the figure above.

(3) The turnaround time of each job
Job1: 25-0=25
Job2: 55-20=35
Job3: 45-20=25
Job4: 75-30=45
Job5: 90-35=55
The right turnaround time of each job
Job1 : 25/25=1
Job2: 35/10=3.5
Job3: 25/20=1.25
Job4: 45/20=2.25
Job5: 55/15=3.67
Average turnaround time = (25+35+25+45+55)/ 5=37
average weighted turnaround time=(1+3.5+1.25+2.25+3.67)/5=2.3

Additional questions
insert image description here
insert image description here

insert image description here

Analysis:
First understand what job scheduling and process scheduling are?
Each job enters the memory through job scheduling, exists in the form of a process, and then executes it through process scheduling.
insert image description here
This problem is a batch operation processing system with two jobs, that is to say, there can only be two jobs in the main memory. Then remember that job scheduling uses a high response ratio priority scheduling algorithm, and process scheduling uses the shortest remaining time priority preemptive scheduling algorithm

  • 10:00 A arrives at the system, there is no job in the main memory, and it directly enters the main memory for execution
  • 10:20 B arrives at the system, there is job A in the main memory, and the CPU is occupied, B enters the main memory and waits
  • 10:30 C arrives at the system. At this moment, there are jobs A and B in the main memory, so C is waiting in the external memory.
  • 10:40 A ends and D arrives in the system. At this moment, only jobs B, C, and D compete to enter the system in the main memory. After the high response ratio priority scheduling algorithm, it is found that the response ratio of C is greater than the response ratio of D, so C enters the main memory. In the main memory, because the remaining running time of B is 30 minutes, and that of C is 50 minutes, it can be concluded that B executes first and C waits through the shortest remaining time priority preemptive scheduling algorithm.
  • 11:10 B ends. At this moment, there is job C in the main memory, and job D directly enters the main memory. In the main memory, because the remaining running time of D is 20 minutes, and that of C is 50 minutes, the shortest remaining time priority preemptive scheduling algorithm is used. It can be concluded that D executes first, and C waits
  • 11:30 D ends, C starts execution
  • 12:20 C End

Reference answer:
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_51453356/article/details/125396747