Skip to content

Commit

Permalink
Resolving Round Robin Errors & Cleaning Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Yahya-Ashraf-Mohamed committed Jan 3, 2023
1 parent 424ed11 commit ff2016b
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 1,199 deletions.
20 changes: 8 additions & 12 deletions Events_Log.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
At time 2 process 4 started arr 17 total 20 remain 20 wait -15
At time 12 process 4 stopped arr 17 total 20 remain 10 wait -15
At time 12 process 1 started arr 2 total 10 remain 10 wait 10
At time 21 process 1 finished arr 2 total 10 remain 0 wait 10 TA 19 WTA 1.90
At time 21 process 2 started arr 5 total 4 remain 4 wait 16
At time 25 process 2 finished arr 5 total 4 remain 0 wait 16 TA 20 WTA 5.00
At time 25 process 3 started arr 7 total 3 remain 3 wait 18
At time 28 process 3 finished arr 7 total 3 remain 0 wait 18 TA 21 WTA 7.00
At time 28 process 4 resumed arr 17 total 20 remain 10 wait 1
At time 38 process 4 finished arr 17 total 20 remain 0 wait 1 TA 21 WTA 1.05
At time 38 process 4 started arr 17 total 20 remain 20 wait 21
At time 57 process 4 finished arr 17 total 20 remain 0 wait 21 TA 40 WTA 2.00
At time 2 process 1 started arr 2 total 10 remain 10 wait 0
At time 12 process 1 finished arr 2 total 10 remain 0 wait 0 TA 10 WTA 1.00
At time 12 process 2 started arr 5 total 4 remain 4 wait 7
At time 16 process 2 finished arr 5 total 4 remain 0 wait 7 TA 11 WTA 2.75
At time 16 process 3 started arr 7 total 3 remain 3 wait 9
At time 19 process 3 finished arr 7 total 3 remain 0 wait 9 TA 12 WTA 4.00
At time 19 process 4 started arr 17 total 20 remain 20 wait 2
At time 39 process 4 finished arr 17 total 20 remain 0 wait 2 TA 22 WTA 1.10
1 change: 1 addition & 0 deletions Header_File/Event_Struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void PrintEvent_Console(const Event *pEvent)
printf("\n");
}

//print event using the same output file format
void PrintEvent_File(const Event *pEvent, FILE *pFile)
{
fprintf(pFile, "At time %d ", pEvent->Time_Step);
Expand Down
3 changes: 0 additions & 3 deletions How to run.txt

This file was deleted.

10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ build:
gcc process_generator.c -o process_generator.out
gcc clk.c -o clk.out
gcc Round_Robin.c -o RR.out
gcc PHPF.c -o PHPF.out
gcc SRTN.c -o SRTN.out
gcc SJF.c -o SJF.out

gcc process.c -o process.out
gcc test_generator.c -o test_generator.out

clean:
rm -f *.out processes.txt
rm -f *.out

all: clean build

run:
./process_generator.out


complete:

123 changes: 0 additions & 123 deletions Min_Heap.c

This file was deleted.

Binary file removed PG.out
Binary file not shown.
17 changes: 0 additions & 17 deletions README

This file was deleted.

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Process-Scheduler
This project is a CPU scheduler which used the following scheduling algorithms using C.
========================================================================================
1. Preemptive Highest Priority First (PHPF).
2. Shortest Remaining time Next (SRTN).
3. Short Job First (SJF).
4. Round Robin (RR).

## Authors
* Yahya Mohamed
* Mariam Moktar
* Muhammed Essam
* Yassmen Abosaif

## generating the files & building
```bash
make all
./test_generator.out
```

## running
```bash
make run
```
Binary file removed RR.out
Binary file not shown.
22 changes: 16 additions & 6 deletions Round_Robin.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Process_Termination(int);
int isTie();

unsigned int Quanta;
unsigned int Number_Of_Process; // Number of proccess readed from input file
unsigned int Number_Of_Process; // Number of proccess readed from input file

queue Process_Queue; //main processes queue
event_queue Event_Queue; //queue for generated events to be excuted later
Expand Down Expand Up @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) {
pause(); // Wait for the first process to arrive
unsigned int start_time = getClk(); // Get the start time

while (ProcDequeue(Process_Queue, &pCurrentProcess) /*|| Number_Of_Process!=0*/) // While processes queue is not empty or their is a process that will be sent
while (ProcDequeue(Process_Queue, &pCurrentProcess) && Number_Of_Process!=0) // While processes queue is not empty or their is a process that will be sent
{

if (isTie()) // Check if their is a tie & if yes put them in the heap
Expand All @@ -63,16 +63,17 @@ int main(int argc, char *argv[]) {
{
pCurrentProcess = HeapPop(Process_Heap); // Get highest priority process
// Cretical section!
Switch_Context_Flag = 0; //turn off switching [LOCK]
Execute_Process(); //execute current process
Switch_Context_Flag = 0; //turn off context switching [LOCK]

while (!Switch_Context_Flag) //as long as this flag is set to zero keep pausing until Alarm Signal is sent
pause(); // To Avoid Busy Waiting
}
continue; //after handling all tie processes skip below and dequeue a new process from main queue
}

// Cretical section!
Switch_Context_Flag = 0; //turn off switching [LOCK]
Switch_Context_Flag = 0; //turn off context switching [LOCK]
Execute_Process(); //execute current process
while (!Switch_Context_Flag) //as long as this flag is set to zero keep pausing until Alarm Signal is sent
pause(); // To Avoid Busy Waiting
Expand All @@ -99,15 +100,18 @@ void Process_Arrival_Handler(int signum)
{
//keep looping as long as a process was received in the current iteration
while (!Receive_Process());

signal(SIGUSR1, Process_Arrival_Handler); // Re-bind SIGUSR1 with Process_Arrival_Handler
}


int Receive_Process()
{
Message msg;
// receive a message or return immediately if their is no proecees
if (msgrcv(Received_MsgQueue_Id, (void *) &msg, sizeof(msg.mProcess), 0, IPC_NOWAIT) == -1) {
perror("RoundRobin: Error while receiving!");
int state = msgrcv(Received_MsgQueue_Id, (void *) &msg, sizeof(msg.mProcess), 0, IPC_NOWAIT);
if (state == -1) {
//perror("RoundRobin: Error while receiving!");
return -1;
}

Expand Down Expand Up @@ -162,6 +166,8 @@ void Alarm_Handler(int signum)
AddEvent(STOP);

Switch_Context_Flag = 1; // flag == 1 so main loop knows it's time to switch context [UNLOCK]

signal(SIGALRM, Alarm_Handler); // Re-bind SIGALRM with Alarm_Handler
}


Expand Down Expand Up @@ -191,6 +197,8 @@ void Execute_Process() {
//initial wait time for the process (Start time - Arival time)
pCurrentProcess->WaitTime = getClk() - pCurrentProcess->ArrivalTime;
AddEvent(START); // Create a start event

Number_Of_Process = Number_Of_Process -1;
}
// [Case 2] the process was stopped and its turn to resume
else
Expand Down Expand Up @@ -285,6 +293,8 @@ void Process_Termination(int signum)

Switch_Context_Flag = 1; //set flag to 1 so main loop knows it's time to switch context as
// if the process Finished before quanta time Ends other process will start

signal(SIGCHLD, Process_Termination); // Re-bind SIGCHLD with Process_Termination
}

int isTie()
Expand Down
Loading

0 comments on commit ff2016b

Please sign in to comment.