You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CPU Scheduling Algorithms/README.md
+132Lines changed: 132 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -67,3 +67,135 @@ The **FCFS** scheduling algorithm follows a non-preemptive approach where proces
67
67
To run this program, you need:
68
68
- A C compiler like `gcc`.
69
69
- Basic command-line skills for compiling and executing C programs.
70
+
71
+
72
+
73
+
74
+
75
+
76
+
# Process Scheduling Simulation in C (Shortest Job First Algorithm)
77
+
78
+
## Table of Contents
79
+
-[Algorithm Overview](#algorithm-overview)
80
+
-[Features](#features)
81
+
-[Shortest Job First (SJF) Algorithm](#shortest-job-first-sjf-algorithm)
82
+
-[Detailed Explanation of Functions](#detailed-explanation-of-functions)
83
+
-[Requirements](#requirements)
84
+
-[Installation and Execution](#installation-and-execution)
85
+
-[Example Usage](#example-usage)
86
+
-[Output Explanation](#output-explanation)
87
+
-[Memory Management](#memory-management)
88
+
-[Code Structure and Files](#code-structure-and-files)
89
+
-[Contributing](#contributing)
90
+
-[License](#license)
91
+
92
+
## Algorithm Overview
93
+
94
+
This algorithm simulates a **Shortest Job First (SJF) scheduling** algorithm for processes in an operating system. In SJF scheduling, the CPU selects the process with the shortest burst time first, ensuring that shorter processes are completed before longer ones. This code calculates and displays essential metrics like **response time**, **turnaround time**, and **waiting time** for each process.
95
+
96
+
The SJF algorithm is a non-preemptive scheduling algorithm and is particularly efficient when short processes need to be prioritized for faster completion.
97
+
98
+
## Features
99
+
100
+
-**Sorts processes by burst time** to ensure the Shortest Job First order.
101
+
-**Calculates Response Time** (time between arrival and first execution).
102
+
-**Calculates Turnaround Time** (total time from arrival to completion).
103
+
-**Calculates Waiting Time** (time spent waiting in the queue).
104
+
-**Displays Results** in a well-formatted table, showing calculated metrics for each process.
105
+
106
+
## Shortest Job First (SJF) Algorithm
107
+
108
+
The **SJF** scheduling algorithm follows a non-preemptive approach where processes are executed based on the shortest burst time first. Here’s how it works in this program:
109
+
110
+
1.**Sorting by Burst Time**: The program first sorts all processes by their burst time. If two processes have the same burst time, they are further sorted by their arrival time.
111
+
2.**Sequential Execution**: Each process begins execution as soon as the CPU is available, based on the completion of the previous process.
112
+
3.**Metric Calculation**: For each process, the program calculates:
113
+
-**Start Time**: When the process begins execution.
114
+
-**Completion Time**: When the process finishes execution.
115
+
-**Response Time**: Difference between start time and arrival time.
116
+
-**Turnaround Time**: Difference between completion time and arrival time.
117
+
-**Waiting Time**: Difference between turnaround time and burst time.
118
+
119
+
## Detailed Explanation of Functions
120
+
121
+
### 1. `find_tat(struct Process* input, int n)`
122
+
- Calculates the **turnaround time** for each process.
123
+
- Formula: **Turnaround Time** = `completion time - arrival time`
124
+
125
+
### 2. `find_wt(struct Process* input, int n)`
126
+
- Calculates the **waiting time** for each process.
127
+
- Formula: **Waiting Time** = `turnaround time - burst time`
128
+
129
+
### 3. `schedule(struct Process* input, int n)`
130
+
- Sorts processes by burst time using the SJF approach.
131
+
- Determines **start time** and **completion time** for each process based on its burst time and order of execution.
132
+
133
+
### 4. `comp(const void* a, const void* b)`
134
+
- Comparison function used by `qsort` to sort processes by burst time, and by arrival time if burst times are equal.
135
+
136
+
## Requirements
137
+
# Process Scheduling Simulation in C (Shortest Job First Algorithm)
138
+
139
+
## Table of Contents
140
+
-[Algorithm Overview](#algorithm-overview)
141
+
-[Features](#features)
142
+
-[Shortest Job First (SJF) Algorithm](#shortest-job-first-sjf-algorithm)
143
+
-[Detailed Explanation of Functions](#detailed-explanation-of-functions)
144
+
-[Requirements](#requirements)
145
+
-[Installation and Execution](#installation-and-execution)
146
+
-[Example Usage](#example-usage)
147
+
-[Output Explanation](#output-explanation)
148
+
-[Memory Management](#memory-management)
149
+
-[Code Structure and Files](#code-structure-and-files)
150
+
-[Contributing](#contributing)
151
+
-[License](#license)
152
+
153
+
## Algorithm Overview
154
+
155
+
This algorithm simulates a **Shortest Job First (SJF) scheduling** algorithm for processes in an operating system. In SJF scheduling, the CPU selects the process with the shortest burst time first, ensuring that shorter processes are completed before longer ones. This code calculates and displays essential metrics like **response time**, **turnaround time**, and **waiting time** for each process.
156
+
157
+
The SJF algorithm is a non-preemptive scheduling algorithm and is particularly efficient when short processes need to be prioritized for faster completion.
158
+
159
+
## Features
160
+
161
+
-**Sorts processes by burst time** to ensure the Shortest Job First order.
162
+
-**Calculates Response Time** (time between arrival and first execution).
163
+
-**Calculates Turnaround Time** (total time from arrival to completion).
164
+
-**Calculates Waiting Time** (time spent waiting in the queue).
165
+
-**Displays Results** in a well-formatted table, showing calculated metrics for each process.
166
+
167
+
## Shortest Job First (SJF) Algorithm
168
+
169
+
The **SJF** scheduling algorithm follows a non-preemptive approach where processes are executed based on the shortest burst time first. Here’s how it works in this program:
170
+
171
+
1.**Sorting by Burst Time**: The program first sorts all processes by their burst time. If two processes have the same burst time, they are further sorted by their arrival time.
172
+
2.**Sequential Execution**: Each process begins execution as soon as the CPU is available, based on the completion of the previous process.
173
+
3.**Metric Calculation**: For each process, the program calculates:
174
+
-**Start Time**: When the process begins execution.
175
+
-**Completion Time**: When the process finishes execution.
176
+
-**Response Time**: Difference between start time and arrival time.
177
+
-**Turnaround Time**: Difference between completion time and arrival time.
178
+
-**Waiting Time**: Difference between turnaround time and burst time.
179
+
180
+
## Detailed Explanation of Functions
181
+
182
+
### 1. `find_tat(struct Process* input, int n)`
183
+
- Calculates the **turnaround time** for each process.
184
+
- Formula: **Turnaround Time** = `completion time - arrival time`
185
+
186
+
### 2. `find_wt(struct Process* input, int n)`
187
+
- Calculates the **waiting time** for each process.
188
+
- Formula: **Waiting Time** = `turnaround time - burst time`
189
+
190
+
### 3. `schedule(struct Process* input, int n)`
191
+
- Sorts processes by burst time using the SJF approach.
192
+
- Determines **start time** and **completion time** for each process based on its burst time and order of execution.
193
+
194
+
### 4. `comp(const void* a, const void* b)`
195
+
- Comparison function used by `qsort` to sort processes by burst time, and by arrival time if burst times are equal.
196
+
197
+
## Requirements
198
+
199
+
To run this program, you need:
200
+
- A C compiler like `gcc`.
201
+
- Basic command-line skills for compiling and executing C programs.
0 commit comments