Saved Programs
Saved Programs
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
if (pid == 0) {
// Child process
printf("Child process ID: %d, Parent process ID: %d\n", getpid(), getppid());
// Parent process
wait(NULL);
} else {
// Error
perror("fork");
return 0;
}
FCFS Scheduling
#include <stdio.h>
int main() {
printf("Enter n: ");
scanf("%d", &n);
scanf("%d", &bt[i]);
wt[0] = 0;
avwt += wt[i];
avtat += tat[i];
avwt /= n;
avtat /= n;
printf("\nProcess\tBurst Time\tWaiting Time\tTurnaround Time\n");
return 0;
}
Bubble Sort with Average TAT and WT
#include <stdio.h>
int main() {
scanf("%d", &n);
scanf("%d", &bt[i]);
temp = bt[j];
bt[j + 1] = temp;
wt[0] = 0;
avwt += wt[i];
avtat += tat[i];
avwt /= n;
avtat /= n;
return 0;
}
Priority Scheduling
#include <stdio.h>
int main() {
scanf("%d", &n);
temp = pr[j];
pr[j + 1] = temp;
temp = bt[j];
bt[j + 1] = temp;
wt[0] = 0;
avwt += wt[i];
avtat += tat[i];
avwt /= n;
avtat /= n;
return 0;
}
Best Fit Memory Allocation
#include <stdio.h>
struct Process {
int pid;
int size;
};
struct Partition {
int pid;
int size;
int isFree;
};
f[best].size))
best = j;
if (best != -1) {
f[best].isFree = 0;
f[best].pid = p[i].pid;
} else {
printf("P%d not allocated\n", p[i].pid);
int main() {
struct Process p[] = {{1, 10}, {2, 20}, {3, 15}, {4, 5}, {5, 18}};
struct Partition f[] = {{1, 25, 1}, {2, 15, 1}, {3, 10, 1}, {4, 20, 1}, {5, 18, 1}};
bestFit(p, f, n, m);
return 0;
}
First Fit Memory Allocation
#include <stdio.h>
int main() {
a[i] = j;
b[j] -= p[i];
break;
printf("%d\t\t\t%d\t\t\t", i + 1, p[i]);
return 0;
}
FIFO Page Replacement
#include <stdio.h>
int main() {
int frames = 3;
int page_faults = 0;
int m[frames];
m[i] = -1;
int ptr = 0;
int page_found = 0;
if (m[j] == pages[i]) {
page_found = 1;
break;
if (page_found == 0) {
m[ptr] = pages[i];
page_faults++;
}
return 0;