提问人:Amanari 提问时间:11/17/2023 最后编辑:CompoAmanari 更新时间:11/17/2023 访问量:43
循环计划批处理脚本的问题 - 等待和周转时间计算不正确
Issue with Round Robin Scheduling Batch Script - Incorrect Calculation of Waiting and Turnaround Times
问:
我在批处理文件中为给定数量的进程、突发时间和时间量程实现了一个循环调度算法。
但是,输出显示等待时间和周转时间的计算不正确。
我需要帮助来识别和修复问题。
@echo off
setlocal enabledelayedexpansion
REM Round Robin Scheduling Batch File
REM Input: Number of processes
set /p n=Enter the number of processes:
REM Initialize arrays to store burst times, waiting times, and turnaround times
set "burst_times="
set /a total_waiting_time=0
set /a total_turnaround_time=0
REM Input: Burst times for each process
for /L %%i in (1,1,%n%) do (
set /p "burst=Enter burst time for P[%%i]: "
set "burst_times=!burst_times! !burst!"
)
REM Input: Time quantum
set /p quantum=Enter the time quantum:
REM Ensure the input is not empty
if %quantum% lss 1 (
echo Quantum time must be greater than 0. Please enter a valid quantum time.
pause
goto :start
)
echo.
echo Process ^| Burst Time ^| Waiting Time ^| Turnaround Time
echo ---------------------------------------------------------
REM Perform Round Robin scheduling
for /L %%i in (1,1,%n%) do (
set /a waiting_time=0
set /a turnaround_time=0
set "current_process=P[%%i]"
for %%t in (!burst_times!) do (
set /a remaining_burst=!burst!-%%t
if !remaining_burst! geq 0 (
set /a waiting_time+=%%t
set /a turnaround_time=!waiting_time
set "burst=!remaining_burst!"
set "burst_times=!burst_times:*%%t=!"
) else (
set /a waiting_time+=%quantum%
set /a turnaround_time=!waiting_time
set "burst_times=!burst_times:*%%t=! !burst_times:*%%t=!"
)
)
set /a total_waiting_time+=waiting_time
set /a total_turnaround_time+=turnaround_time
echo !current_process! ^| !burst! ^| !waiting_time! ^| !turnaround_time!
)
REM Calculate and display average waiting time and average turnaround time
set /a avg_waiting_time=total_waiting_time/n
set /a avg_turnaround_time=total_turnaround_time/n
echo ---------------------------------------------------------
echo.
echo Average Waiting Time: %avg_waiting_time% ms
echo Average Turnaround Time: %avg_turnaround_time% ms
pause
答: 暂无答案
评论
/n
total_waiting_time/n
!waiting_time
set "burst_times=!burst_times! !burst!"
burst_times[%%i]
set /a
set /a avg_waiting_time=total_waiting_time/n
set /a avg_turnaround_time=total_turnaround_time/n
4.6
4
26.3333
26
n
Number of processes
CALL :calc_ 5 !avg_turnaround_time!/!n!
!calc_v!
5