Os Program
Os Program
h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
If (argc < 3) {
Exit(1);
Int pid;
Char s[100];
Pid = fork();
If (pid < 0) {
Perror(“Fork failed”);
Exit(1);
Printf(“\nParent Process:\n”);
// If execlp fails
Exit(1);
Printf(“\nChild Process:\n”);
Execvp(argv[2], &argv[2]);
// If execvp fails
Exit(1);
Return 0;
Fcfs algorithm
#include <stdio.h>
Int main() {
Int n, i;
Scanf(“%d”, &n);
Int bt[n], wt[n], tat[n]; // Burst time, waiting time, turnaround time
Scanf(“%d”, &bt[i]);
// Display results
Return 0;
}
Sjn
#include <stdio.h>
Int main() {
Int n;
Scanf(“%d”, &n);
Scanf(“%d”, &bt[i]);
}
sortProcesses(n, bt, p); // Sort processes by Burst Time
Wt[0] = 0;
// Display Results
Return 0;
Round robin
#include <stdio.h>
Remaining_bt[i] = bt[i];
If (remaining_bt[i] > 0) {
Time += tq;
Remaining_bt[i] -= tq;
} else {
Time += remaining_bt[i];
Remaining_bt[i] = 0;
// Display results
Int main() {
Int n, tq;
Scanf(“%d”, &n);
Int bt[n];
Scanf(“%d”, &bt[i]);
Scanf(“%d”, &tq);
return 0;
Priority scheduling
#include <stdio.h>
Int main() {
Int n;
Scanf(“%d”, &n);
Wt[0] = 0;
// Display Results
Return 0;
Dining philosopher
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
Void one();
Void two();
Int main() {
Int i;
Scanf(“%d”, &tph);
Philname[i] = (i + 1);
Scanf(“%d”, &howhung);
If (howhung == tph) {
Printf(“\nExiting..\n”);
Return 0;
} else {
Scanf(“%d”, &hu[i]);
Do {
Printf(“\n3. Exit”);
Printf(“\nEnter your choice: “);
Scanf(“%d”, &cho);
Switch (cho) {
Case 3: return 0;
} while (1);
Return 0;
Void one() {
Int pos = 0, x, i;
Void two() {
Int i, j, s = 0, t, r, x;
If (abs(hu[i] – hu[j]) >= 1 && abs(hu[i] – hu[j]) != 4) { // Condition for valid pair
T = hu[i];
R = hu[j];
S++;