Os24 Pa03
Os24 Pa03
CPU Scheduling
Spring, 2024
Deadline: May 19, before 24:00
Overview
PA3-2
Outline
PA3-3
Outline
PA3-4
Detail
• Design Hint
• It is recommended that you start this assignment by defining a
data structure similar to a Process Control Block (PCB) for each
task.
• You need to implement linked lists as the process queue
structure.
• System Model
• Assume that there are 10 processes in the job queue of your
(virtual) system.
• Initially, all the processes (10 processes) are in NEW state.
• A process may enter the ready queue if it arrives according to the
task information which is determined by user’s input
• The input is delivered through a “file” that specifies each
process’s arrival time and CPU burst requests.
PA3-5
1. User’s Input
• The task (process) information will be read from an input file.
• The file format:
• Each line of the file has the following format:
• pid priority arrival_time burst_time
• All of fields are integer types, where
• pid is a unique numeric process ID (1 to 10)
• (maximum value is 10)
• priority is an integer value
• A larger value implies a higher priority
• arrival_time is the time when the task arrives in the unit of milliseconds
• burst_time the is the CPU time requested by a task, in the unit of
milliseconds
• Assume the time units for arrival_time, burst_time and interval are in millisecond units.
• Sample input : input.dat
1 50 10 50
2 50 0 40
3 30 20 50
5 10 7 35
PA3-6
2. Requirements
• Simulate (i.e., implement) the following three CPU scheduling
algorithms
• First-Come, First-Served (FCFS) Scheduling
• Round-Robin (RR) Scheduling
• Preemptive Priority Scheduling (with Aging)
PA3-7
3. Output
⚫ Print time-flow (like Gantt chart) and statistical information
for each algorithm
⚫ Sample output (the output is saved into a file or printed out on the
screen)
Scheduling : FCFS Scheduling : RR
========================================== ==========================================
<time 0> ---- system is idle ---- <time 0> ---- system is idle ----
<time 1> ---- system is idle ---- <time 1> ---- system is idle ----
<time 2> [new arrival] process 1 <time 2> [new arrival] process 1
<time 2> process 1 is running <time 2> process 1 is running
<time 3> process 1 is running <time 3> process 1 is running
<time 4> process 1 is running <time 4> process 1 is running
<time 5> process 1 is running <time 5> process 1 is running
<time 6> [new arrival] process 2 <time 6> [new arrival] process 2
<time 6> process 1 is running <time 6> process 1 is running
<time 7> process 1 is finished <time 7> process 1 is finished
------------------------------- (Context-Switch) ------------------------------- (Context-Switch)
<time 8> process 2 is running <time 8> process 2 is running
… …
<time 50> all processes finish <time 50> all processes finish
========================================== ==========================================
Avarage cpu usage : 92.00 % Avarage cpu usage : 92.00 %
Avarage waiting time : 15.2 Avarage waiting time : 7.2
Avarage response time : 12.1 Avarage response time : 7.1
Avarage turnaround time: 21.0 Avarage turnaround time: 18.0
PA3-8
4. Details on Priority Scheduling
• The priority level of a process is represented by the
priority field
• (pid priority arrival_time burst_time)
• The priority scheduler selects the process with the highest
priority value to run next.
• Aging
• To prevent the starvation, you will implement an aging scheme. The priority of a
process varies over time according to:
f( t ) = alpha * t
PA3-9
1’. User’s input
• Task(job) Information is delivered to your simulator using “command
line arguments”
• In the C, it is very common to use the command line arguments for
parameter configuration and/or acceptance of user’s input.
• Example:
• > os23 scenario1.dat output1.txt 5 0.2
PA3-10
Command line argument in the C ?
⚫ A way for accepting program’s arguments in C using argc and argv
⚫ Your main() function may look like:
int
⚫ intmain
argc ( int argc, char *argv[] )
⚫ the argument count.
⚫ It is the number of arguments passed into the program from the command line,
including the name of the program.
⚫ char* argv[]
⚫ the listing of all the arguments.
⚫ argv[0] is the name of the program, or an empty string if the name is not available.
After that, every element number less than argc is a command line argument.
⚫ You can use each argv element just like a string, or use argv as a two dimensional
array. argv[argc] is a null pointer.
⚫ Example
⚫ > os24 scenario1.dat output1.txt 5 0.2
⚫ argc = ?
⚫ argv[3] = ?
PA3-11
Command line argument in the C ?
Example code
#include <stdio.h>
int main ( int argc, char *argv[] )
{
if ( argc != 2 ) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "usage: %s filename", argv[0] );
}
else
{
// We assume argv[1] is a filename to open
FILE *file = fopen( argv[1], "r" );
/* fopen returns 0, the NULL pointer, on failure */
if ( file == 0 )
{
printf( "Could not open file\n" );
}
else
{
int x;
/* read one character at a time from file, stopping at EOF, which
indicates the end of the file. Note that the idiom of "assign
to a variable, check the value" used below works because
the assignment statement evaluates to the value assigned. */
while ( ( x = fgetc( file ) ) != EOF )
{
printf( "%c", x );
}
fclose( file );
}
}
}
PA3-12
5. Design Hints
⚫ Recommendation
⚫ You can use a data structure similar to a Process Control Block (PCB) for each task,
though yours will be much simpler.
⚫ Two queues are maintained; one for the job queue and one for the ready queue
⚫ The job queue may be implemented simply with an Array!
⚫ and the ready queue with a linked-list
⚫ Simulator
⚫ The simulator first initializes the job queue and the data structure of PCB information for
10 processes (which are set to be in the NEW state – this is our assumption)
⚫ The simulator then reads the task information from the input file and stores all data in a
data structure.
⚫ Then, start simulating a scheduling algorithm in a time-driven manner.
⚫ At each time unit (or slot), it adds any newly arrived task(s) into the ready queue and
runs a specific scheduler algorithm in order to select appropriate task from ready queue.
⚫ When a task is chosen to run, the simulator prints out a message indicating what
process ID is chosen to execute for this time slot. If no task is running (i.e. empty ready
queue), it prints out an “idle” message.
⚫ Before advancing to the next time unit, the simulator should make all necessary
changes in job and ready queue status.
PA3-13
Submission
• Program Report using POWER-POINT(PPT)
• 3-5 pages explaining your Program (data structure, functions
etc.)
• Screen capture of execution for 3 or more command-line
input strings (입력)
• Last page
• Performance results (성능평가) of each scheduling algorithm
• waiting time, …
• You may use graphs to show your results
• Submission
• A zip file, which contains
• All source code files (.c), your test input files
• PPT file
• File naming: Student#_YourName.zip (ex: 20232232_홍길동.zip)
PA3-14
Grading policy
• 50 points (Approx. 5% of your semester grades).
• FCFS (20), RR (10), Preemptive Priority Scheduling with
Aging (10), Documentation(PPT) (10)
• Degradation
• If you do not follow the requirements:
• File naming, contents (-10%)
• Delayed submission: at least -50% points
• Compile error : -50%
• Copied from previous year submissions, classmates: 0
points
• Individual assignment ! (No collaboration)
PA3-15
Appendix (RR)
PA3-16
ChatGPT 활용 레포트
본 과제 리포트에 아래 1~6번 수행한 사항을 추가로 *별도 파일*로 리포트를 작성하여 제출하길
바랍니다.
PA3-17
Questions
PA3-18