🔹 1. FCFS Scheduling Algorithm
Explanation:
FCFS (First Come First Serve) executes processes in the order they arrive.
#include <stdio.h>
int main() {
int n, i;
printf("Enter number of processes: ");
scanf("%d", &n);
int bt[n], wt[n], tat[n];
for(i = 0; i < n; i++) {
printf("Enter burst time for P%d: ", i+1);
scanf("%d", &bt[i]);
}
wt[0] = 0;
for(i = 1; i < n; i++)
wt[i] = wt[i-1] + bt[i-1];
for(i = 0; i < n; i++)
tat[i] = wt[i] + bt[i];
printf("\nProcess\tBT\tWT\tTAT\n");
for(i = 0; i < n; i++)
printf("P%d\t%d\t%d\t%d\n", i+1, bt[i], wt[i], tat[i]);
return 0;
}
🔹 2. SJF Scheduling Algorithm
Explanation:
SJF (Shortest Job First) executes the process with the smallest burst time first.
#include <stdio.h>
int main() {
int n, i, j;
printf("Enter number of processes: ");
scanf("%d", &n);
int bt[n], wt[n], tat[n];
for(i = 0; i < n; i++) {
printf("Enter burst time: ");
scanf("%d", &bt[i]);
}
for(i = 0; i < n-1; i++) {
for(j = i+1; j < n; j++) {
if(bt[i] > bt[j]) {
int temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;
}
}
}
wt[0] = 0;
for(i = 1; i < n; i++)
wt[i] = wt[i-1] + bt[i-1];
for(i = 0; i < n; i++)
tat[i] = wt[i] + bt[i];
printf("\nBT\tWT\tTAT\n");
for(i = 0; i < n; i++)
printf("%d\t%d\t%d\n", bt[i], wt[i], tat[i]);
return 0;
}
🔹 3. Priority Scheduling
Explanation:
Processes are executed based on priority (lower number = higher priority).
#include <stdio.h>
int main() {
int n, i, j;
printf("Enter number of processes: ");
scanf("%d", &n);
int bt[n], pr[n];
for(i = 0; i < n; i++) {
printf("Enter burst time and priority: ");
scanf("%d%d", &bt[i], &pr[i]);
}
for(i = 0; i < n-1; i++) {
for(j = i+1; j < n; j++) {
if(pr[i] > pr[j]) {
int t = bt[i]; bt[i] = bt[j]; bt[j] = t;
t = pr[i]; pr[i] = pr[j]; pr[j] = t;
}
}
}
printf("\nProcess\tBT\tPriority\n");
for(i = 0; i < n; i++)
printf("P%d\t%d\t%d\n", i+1, bt[i], pr[i]);
return 0;
}
🔹 4. Round Robin Scheduling
Explanation:
Each process gets fixed time (time quantum) in cyclic order.
#include <stdio.h>
int main() {
int n, tq, i, total = 0;
printf("Enter number of processes: ");
scanf("%d", &n);
int bt[n], rem[n];
for(i = 0; i < n; i++) {
printf("Enter burst time: ");
scanf("%d", &bt[i]);
rem[i] = bt[i];
}
printf("Enter time quantum: ");
scanf("%d", &tq);
while(1) {
int done = 1;
for(i = 0; i < n; i++) {
if(rem[i] > 0) {
done = 0;
if(rem[i] > tq) {
total += tq;
rem[i] -= tq;
} else {
total += rem[i];
printf("Process %d finished at %d\n", i+1, total);
rem[i] = 0;
}
}
}
if(done == 1) break;
}
return 0;
}
🔹 Memory Allocation Algorithms (5–8)
🔹 5. First Fit
Explanation: First available block is allocated.
#include <stdio.h>
int main() {
int b[5]={100,500,200,300,600};
int p[3]={212,417,112};
for(int i=0;i<3;i++) {
for(int j=0;j<5;j++) {
if(b[j] >= p[i]) {
printf("Process %d allocated to block %d\n", i+1, j+1);
b[j] -= p[i];
break;
}
}
}
}
🔹 6. Best Fit
Explanation: Smallest suitable block is selected.
#include <stdio.h>
int main() {
int b[5]={100,500,200,300,600};
int p[3]={212,417,112};
for(int i=0;i<3;i++) {
int best=-1;
for(int j=0;j<5;j++) {
if(b[j]>=p[i] && (best==-1 || b[j]<b[best]))
best=j;
}
if(best!=-1) {
printf("Process %d -> Block %d\n", i+1, best+1);
b[best]-=p[i];
}
}
}
🔹 7. Next Fit
Explanation: Allocation starts from last allocated block.
#include <stdio.h>
int main() {
int b[5]={100,500,200,300,600};
int p[3]={212,417,112};
int last=0;
for(int i=0;i<3;i++) {
int j=last, count=0;
while(count<5) {
if(b[j]>=p[i]) {
printf("Process %d -> Block %d\n", i+1, j+1);
b[j]-=p[i];
last=j;
break;
}
j=(j+1)%5;
count++;
}
}
}
🔹 8. Worst Fit
Explanation: Largest block is selected.
#include <stdio.h>
int main() {
int b[5]={100,500,200,300,600};
int p[3]={212,417,112};
for(int i=0;i<3;i++) {
int worst=-1;
for(int j=0;j<5;j++) {
if(b[j]>=p[i] && (worst==-1 || b[j]>b[worst]))
worst=j;
}
if(worst!=-1) {
printf("Process %d -> Block %d\n", i+1, worst+1);
b[worst]-=p[i];
}
}
}
🔹 9. Basic Linux Commands (Any 10)
Explanation: Basic commands used in Linux OS.
| Command | Description |
|---|---|
ls | List files |
pwd | Show current directory |
cd | Change directory |
mkdir | Create directory |
rmdir | Remove directory |
touch | Create file |
rm | Delete file |
cp | Copy file |
mv | Move file |
cat | Display file content |
$ pwd
/home/user
$ ls
file1.txt file2.txt
$ mkdir test
$ ls
file1.txt file2.txt test
$ cd test
$ pwd
/home/user/test
$ touch a.txt
$ ls
a.txt
$ cat a.txt
(Empty file)
$ cp a.txt b.txt
$ ls
a.txt b.txt
$ mv b.txt c.txt
$ ls
a.txt c.txt
$ rm a.txt
$ ls
c.txt
$ cd ..
$ rmdir test

0 Comments