os slip1
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
pid_t child_pid;
child_pid = fork();
if (child_pid == 0) {
printf("Child process with PID: %d\n", getpid());
nice(10);
printf("Child process priority increased\n");
} else if (child_pid > 0) {
printf("Parent process with PID: %d\n", getpid());
wait(NULL);
} else {
perror("Fork failed");
return 1;}
return 0;}
Q.2 Write the simulation program to implement demand paging and show the page scheduling and total number of page faults for the following given page reference string. Give input
n=3 as the number of memory frames. Reference String :3, 4, 5, 6, 3, 4, 7, 3, 4, 5, 6, 7, 2, 4, 6 Implement FIFO
ANSWER-2
#include <stdio.h>
int main() {
int n = 3, memory[3] = {-1}, faults = 0;
int pages[] = {3, 4, 5, 6, 3, 4, 7, 3, 4, 5, 6, 7, 2, 4, 6};
for (int i = 0; i < 15; i++) {
int p = pages[i], found = 0;
for (int j = 0; j < n; j++) {
if (memory[j] == p) {
found = 1;
break;}}
if (!found) {
faults++;
memory[faults % n] = p;}}
printf("Total Page Faults: %d\n", faults);
return 0;