Os Slip Ans
Os Slip Ans
Q1) Create a child process using fork (), display parent and child process id. Child process will display
the message “Hello World” and the parent process should display “Hi”. [10 Marks]
//fork()
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
int main()
int pid;
int status;
pid = fork();
if(pid == -1)
perror("bad fork");
exit(1);
if (pid == 0)
else
wait(&status);
printf("hi %d.\n",getpid());
return 0;
Q2) 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 as the number
of memory frames. Implement FIFO Reference String : 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1
//FIFO
#include <stdio.h>
int main()
int pageFaults = 0;
int frames = 3;
int m, n, s, pages;
pages = sizeof(incomingStream)/sizeof(incomingStream[0]);
int temp[frames];
temp[m] = -1;
s = 0;
if(incomingStream[m] == temp[n])
s++;
pageFaults--;
pageFaults++;
temp[m] = incomingStream[m];
}
else if(s == 0)
printf("\n");
printf("%d\t\t\t",incomingStream[m]);
if(temp[n] != -1)
else
printf(" - \t\t\t");
return 0;
SLIP2
1 . Write a program to illustrate the concept of orphan process ( Using fork() and sleep()).[10marks]
//FORK() SLEEP()
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
int main()
if(pid>0)
{
//getpid() returns process id and getppid() will return parent process id
printf("Parent process\n");
else if(pid==0)
printf("Child process\n");
sleep(5);
else
return 0;
Q2) 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 as the number
of memory frames. Implement OPT Reference String : 12,15,12,18,6,8,11,12,19,12,6,8,12,15,19,8 .
[20Marks]
#include<stdio.h>
int main()
int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1, flag2, flag3, i, j, k, pos, max,
faults = 0;
scanf("%d", &no_of_frames);
scanf("%d", &no_of_pages);
scanf("%d", &pages[i]);
frames[i] = -1;
flag1 = flag2 = 0;
if(frames[j] == pages[i]){
flag1 = flag2 = 1;
break;
if(flag1 == 0){
if(frames[j] == -1){
faults++;
frames[j] = pages[i];
flag2 = 1;
break;
if(flag2 == 0){
flag3 =0;
temp[j] = -1;
if(frames[j] == pages[k]){
temp[j] = k;
break;
if(temp[j] == -1){
pos = j;
flag3 = 1;
break;
if(flag3 ==0){
max = temp[0];
pos = 0;
max = temp[j];
pos = j;
}
frames[pos] = pages[i];
faults++;
printf("\n");
printf("%d\t", frames[j]);
return 0;
SLIP3
Q1) Write a program that demonstrates the use of nice () system call. After a child process is started
using fork (), assign higher priority to the child using nice () system call [10 Marks]
//nice()
#include<unistd.h>
#include<stdlib.h>/* contains prototype for wait */
#include<stdio.h>
int main()
{
int pid;
int retnice;
pid = fork( );
if(pid == -1) /* check for error in fork */
{
perror("bad fork");
exit(1);
}
if (pid == 0)
{
retnice = nice(1);
printf("Child process and Process id = %d.\n",retnice);
sleep(1);
}else
{
retnice= nice(4);
printf("Parent process and Process id = %d.\n", retnice);
sleep(1);
}
}
Q2) 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 as the number of memory frames. Implement LRU Reference String
:12,15,12,18,6,8,11,12,19,12,6,8,12,15,19,8 [20Marks]
//LRU
#include<stdio.h>
int main()
{
int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
printf("Enter no of pages:");
scanf("%d",&n);
printf("Enter the reference string:");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("Enter no of frames:");
scanf("%d",&f);
q[k]=p[k];
printf("\n\t%d\n",q[k]);
c++;
k++;
for(i=1;i<n;i++)
{
c1=0;
for(j=0;j<f;j++)
{
if(p[i]!=q[j])
c1++;
}
if(c1==f)
{
c++;
if(k<f)
{
q[k]=p[i];
k++;
for(j=0;j<k;j++)
printf("\t%d",q[j]);
printf("\n");
}
else
{
for(r=0;r<f;r++)
{
c2[r]=0;
for(j=i-1;j<n;j--)
{
if(q[r]!=p[j])
c2[r]++;
else
break;
}
}
for(r=0;r<f;r++)
b[r]=c2[r];
for(r=0;r<f;r++)
{
for(j=r;j<f;j++)
{
if(b[r]<b[j])
{
t=b[r];
b[r]=b[j];
b[j]=t;
}
}
}
for(r=0;r<f;r++)
{
if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
}
printf("\n");
}
}
}
printf("\nThe no of page faults is %d",c);
}
SLIP4
Q1) Write a program that demonstrates the use of nice () system call. After a child process is started
using fork (), assign higher priority to the child using nice() system call. [10 Marks]
//nice()
#include<unistd.h>
#include<stdlib.h>/* contains prototype for wait */
#include<stdio.h>
int main()
{
int pid;
int retnice;
pid = fork( );
if(pid == -1) /* check for error in fork */
{
perror("bad fork");
exit(1);
}
if (pid == 0)
{
retnice = nice(1);
printf("Child process and Process id = %d.\n",retnice);
sleep(1);
}else
{
retnice= nice(4);
printf("Parent process and Process id = %d.\n", retnice);
sleep(1);
}
}
Q2) 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 as the number
of memory frames. Implement FIFO Reference String :3, 4, 5, 6, 3, 4, 7, 3, 4, 5, 6, 7, 2, 4, 6 [20Marks]
//FIFO
#include <stdio.h>
int main()
int pageFaults = 0;
int frames = 3;
int m, n, s, pages;
pages = sizeof(incomingStream)/sizeof(incomingStream[0]);
int temp[frames];
temp[m] = -1;
s = 0;
if(incomingStream[m] == temp[n])
s++;
pageFaults--;
pageFaults++;
temp[m] = incomingStream[m];
else if(s == 0)
}
printf("\n");
printf("%d\t\t\t",incomingStream[m]);
if(temp[n] != -1)
else
printf(" - \t\t\t");
return 0;
SLIP5
Q1) Create a child process using fork (), display parent and child process id. Child process will display
the message “Hello World” and the parent process should display “Hi”. [10 Marks]
//fork()
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
int main()
int pid;
int status;
pid = fork();
if(pid == -1)
perror("bad fork");
exit(1);
}
if (pid == 0)
else
wait(&status);
printf("hi %d.\n",getpid());
return 0;
Q2) Write the simulation program for demand paging and show the page scheduling and total number
of page faults according to SECOND CHANCE page replacement algorithm. Assume the memory of 3
frames. Request Page Numbers: 9,14,10, 11, 15, 9, 11, 9, 15, 10, 9, 15, 10, 12, 15 [20Marks]
#include<stdio.h>
int refstring[20],pt[10],u[10],nof,nor;
void accept()
int i;
for(i=0;i<nor;i++)
printf("[%d]=",i);
scanf("%d",&refstring[i]);
int search(int s)
int i;
for(i=0;i<nof;i++)
if(pt[i]==s)
return(i);
return(-1);
void second_chance()
int i,j,k,faults=0,sp=0;
for(i=0;i<nor;i++)
printf("%d",refstring[i]);
k=search(refstring[i]);
if(k==-1)
while(1)
if(u[sp]==0)
pt[sp]=refstring[i];
u[sp]=1;
sp=(sp+1)%nof;
faults++;
break;
else
u[sp]=0;
sp=(sp+1)%nof;
}
for(j=0;j<nof;j++)
printf("\n%3d%3d",pt[j],u[j]);
if(j==sp)
printf("*");
printf("\t");
int main()
scanf("%d",&nor);
scanf("%d",&nof);
accept();
second_chance();
getch();
SLIP6
Q1) Write a program to find the execution time taken for executing a given set of instructions (use
clock () function) [10 Marks]
Q2) Partially implement the Menu driven Banker’s algorithm for accepting Allocation, Max from
user.a) Accept Available b) Display Allocation, Max c) Find Need and Display It, d) Display Available
[20Marks]
//bankeralgo
#include<stdio.h>
int main() {
}
printf("enter the max resource process required %dx%d matrix", p, c);
printf("%d\t", need[i][j]);
printf("\n");
/* once process execute variable done will stop them for again execution */
done[i] = 0;
if (done[i] == 0) {
break;
//when need matrix is not greater then available matrix then if j==c will true
if (j == c) {
safe[count] = i;
done[i] = 1;
/* now process get execute release the resources and add them in available resources */
available[j] += alc[i][j];
count++;
terminate = 0;
} else {
terminate++;
if (terminate == (p - 1)) {
break;
if (terminate != (p - 1)) {
printf("%d\t", available[i]);
printf("p%d\t", safe[i]);
}
return 0;
SLIP7
Q1) .Write a program to illustrate the concept of orphan process (Using fork () and sleep ()) [10 Marks]
Q2) 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 as the number
of memory frames. Implement OPT Reference String : 12,15,12,18,6,8,11,12,19,12,6,8,12,15,19,8 [20
Marks]
SLIP8
Q1) Write a program to find the execution time taken for executing a given set of instructions (use
clock () function) [10 Marks] Q2) Write a simulation program using FCFS. The arrival time, CPU burst
time and number of process should be given as input to the system. The output should give the
Turned around time and waiting time for each process and calculate Average Waiting Time and
Turned around Time.[20MARKS]
SLIP9
Q1) Given an initial state of a 8-puzzle problem and final state to be reached
Given:
283
164
7 5
Output:
123
8 4
765
Find the most cost-effective path to reach the final state from initial state using A* Algorithm.
Consider g(n)=Depth of node and h(n)=Number of misplaced tiles [10 Marks]
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include<time.h>
#define r 3
#define c 3
char matrix[r][c];
char new[r][c];
int count;
int i,j;
char z ;
int p,q,x,y;
int t =0;
int result = 0;
void load()
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(new[i][j] == '0')
continue;
}
matrix[i][j]= new[i][j];
void blank()
for(i=0;i<3;i++)
for(j=0;j<3;j++)
int main()
time_t T= time(NULL);
struct tm tm = *localtime(&T);
char f[4];
int rsl ;
int random,t;
int randvalues[9];
main:
count = 0;
blank();
T= time(NULL);
tm = *localtime(&T);
srand(tm.tm_sec);
while(count!=9)
rsl=rand()%9;
sprintf(f,"%d",rsl);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if((new[i][j]) == f[0])
i = 4; j = 4;
continue;
new[i][j] = f[0];
i = 4; j = 4;
count++;
}
}
load();
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("|%c|",matrix[i][j]);
printf("\n");
while(1)
scanf(" %c",&z);
if(z=='q')
printf("\n*****You Quit*****\n");
goto main;
// break;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
if((matrix[i][j])== z)
p = i;
q = j;
x = i;
y = j;
t =0;
int m , n ;
m = p - 1;
n=q;
if(m>=0)
m = p + 1;
if(m<=2)
}
m = p;
n=q-1;
if(n>=0)
n=q+1;
if(n<=2)
if(t==1)
matrix[x][y] = z;
t = 0;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if((matrix[i][j])== final[i][j])
t++;
}
system("clear");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("|%c|",matrix[i][j]);
printf("\n");
if(t==9)
printf("\n****you Win****\n");
break;
return 1;
Q2) Write a simulation program using SJF. The arrival time, CPU burst time and number of process
should be given as input to the system. The output should give the Turned around time and waiting
time for each process and calculate Average Waiting Time and Turned around Time. [ 20 Marks]
//SJF
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int temp=*x;
*x=*y;
*y=temp;
int i, j;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(at[i]>at[j])
swap(&p[i], &p[j]);
swap(&at[i], &at[j]);
swap(&bt[i], &bt[j]);
/* if two processes have the same arrival time than sort them having
else if(at[i]==at[j])
if(bt[i]>bt[j])
swap(&p[i], &p[j]);
swap(&at[i], &at[j]);
swap(&bt[i], &bt[j]);
}
void tatwt( int ct[], int at[], int bt[], int tat[], int wt[], int n)
int i;
for(i=0;i<n;i++)
tat[i]=ct[i]-at[i];
wt[i]=tat[i]-bt[i];
int main()
scanf("%d", &n);
p=(int*)malloc(n*sizeof(int));
at=(int*)malloc(n*sizeof(int));
bt=(int*)malloc(n*sizeof(int));
ct=(int*)malloc(n*sizeof(int));
wt=(int*)malloc(n*sizeof(int));
tat=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
scanf("%d",&p[i]);
for(i=0;i<n;i++)
scanf("%d",&at[i]);
for(i=0;i<n;i++)
scanf("%d",&bt[i]);
ct[0]=at[0] + bt[0];
if(at[j]<=ct[i-1])
if(bt[j]<min)
min=bt[j];
pos=j;
/* when you get less burst time process, swap p, at, bt at position 2,
and when getting 2nd less burst time swap at position 3rd and so on. */
swap(&p[i],&p[pos]);
swap(&at[i],&at[pos]);
swap(&bt[i],&bt[pos]);
min=1000;
ct[i]=ct[i-1]+bt[i];
}tatwt(ct,at,bt,tat,wt,n);
printf("\np\tat\tbt\tct\ttat\twt");
for(i=0;i<n;i++){
printf("\n%d\t%d\t%d\t%d\t%d\t%d",p[i],at[i],bt[i],ct[i],tat[i],wt[i]);
}for(i=0;i<n;i++){
atat+=tat[i];
atat=atat/n;
awt=awt/n;
printf("\navgtat=%.2fandavgwt=%.2f",atat,awt);
return 0;
SLIP10
Q1) Create a child process using fork (), display parent and child process id. Child process will display
the message “Hello World” and the parent process should display “Hi”. [10 Marks]
//fork()
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
int main()
int pid;
int status;
pid = fork();
if(pid == -1)
perror("bad fork");
exit(1);
if (pid == 0)
else
wait(&status);
printf("hi %d.\n",getpid());
return 0;
Q2) partially implement the Menu driven Banker’s algorithm for accepting Allocation, Max from user.
a) Accept Available b) Display Allocation, Max c) Find Need and Display It, d) Display Available
[20Marks]
//bankeralgo
#include<stdio.h>
int main() {
printf("%d\t", need[i][j]);
printf("\n");
/* once process execute variable done will stop them for again execution */
done[i] = 0;
if (done[i] == 0) {
break;
//when need matrix is not greater then available matrix then if j==c will true
if (j == c) {
safe[count] = i;
done[i] = 1;
/* now process get execute release the resources and add them in available resources */
available[j] += alc[i][j];
count++;
terminate = 0;
} else {
terminate++;
if (terminate == (p - 1)) {
break;
if (terminate != (p - 1)) {
printf("%d\t", available[i]);
printf("p%d\t", safe[i]);
return 0;
SLIP11
Q1) Given an initial state of a 8-puzzle problem and final state to be reached
283
164
7 5
123
8 4
7 6 5 Find the most cost-effective path to reach the final state from initial state using A* Algorithm.
Consider g(n)=Depth of node and h(n)=Number of misplaced tiles [10 Marks]
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include<time.h>
#define r 3
#define c 3
char matrix[r][c];
char new[r][c];
int count;
int i,j;
char z ;
int p,q,x,y;
int t =0;
int result = 0;
void load()
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(new[i][j] == '0')
continue;
matrix[i][j]= new[i][j];
}
}
void blank()
for(i=0;i<3;i++)
for(j=0;j<3;j++)
int main()
time_t T= time(NULL);
struct tm tm = *localtime(&T);
char f[4];
int rsl ;
int random,t;
int randvalues[9];
main:
count = 0;
blank();
T= time(NULL);
tm = *localtime(&T);
srand(tm.tm_sec);
while(count!=9)
rsl=rand()%9;
sprintf(f,"%d",rsl);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if((new[i][j]) == f[0])
i = 4; j = 4;
continue;
new[i][j] = f[0];
i = 4; j = 4;
count++;
load();
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("|%c|",matrix[i][j]);
printf("\n");
while(1)
scanf(" %c",&z);
if(z=='q')
printf("\n*****You Quit*****\n");
goto main;
// break;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if((matrix[i][j])== z)
p = i;
q = j;
x = i;
y = j;
t =0;
int m , n ;
m = p - 1;
n=q;
if(m>=0)
m = p + 1;
if(m<=2)
m = p;
n=q-1;
if(n>=0)
{
n=q+1;
if(n<=2)
if(t==1)
matrix[x][y] = z;
t = 0;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if((matrix[i][j])== final[i][j])
t++;
}
system("clear");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("|%c|",matrix[i][j]);
printf("\n");
if(t==9)
printf("\n****you Win****\n");
break;
return 1;
Q2) Write a simulation program using SJF. The arrival time, CPU burst time and number of process
should be given as input to the system. The output should give the Turned around time and waiting
time for each process and calculate Average Waiting Time and Turned around Time. [ 20 Marks]
//SJF
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int temp=*x;
*x=*y;
*y=temp;
int i, j;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(at[i]>at[j])
swap(&p[i], &p[j]);
swap(&at[i], &at[j]);
swap(&bt[i], &bt[j]);
/* if two processes have the same arrival time than sort them having
else if(at[i]==at[j])
if(bt[i]>bt[j])
swap(&p[i], &p[j]);
swap(&at[i], &at[j]);
swap(&bt[i], &bt[j]);
}
}
void tatwt( int ct[], int at[], int bt[], int tat[], int wt[], int n)
int i;
for(i=0;i<n;i++)
tat[i]=ct[i]-at[i];
wt[i]=tat[i]-bt[i];
int main()
scanf("%d", &n);
p=(int*)malloc(n*sizeof(int));
at=(int*)malloc(n*sizeof(int));
bt=(int*)malloc(n*sizeof(int));
ct=(int*)malloc(n*sizeof(int));
wt=(int*)malloc(n*sizeof(int));
tat=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
scanf("%d",&p[i]);
scanf("%d",&at[i]);
for(i=0;i<n;i++)
scanf("%d",&bt[i]);
ct[0]=at[0] + bt[0];
if(at[j]<=ct[i-1])
if(bt[j]<min)
min=bt[j];
pos=j;
/* when you get less burst time process, swap p, at, bt at position 2,
and when getting 2nd less burst time swap at position 3rd and so on. */
swap(&p[i],&p[pos]);
swap(&at[i],&at[pos]);
swap(&bt[i],&bt[pos]);
min=1000;
ct[i]=ct[i-1]+bt[i];
}tatwt(ct,at,bt,tat,wt,n);
printf("\np\tat\tbt\tct\ttat\twt");
for(i=0;i<n;i++){
printf("\n%d\t%d\t%d\t%d\t%d\t%d",p[i],at[i],bt[i],ct[i],tat[i],wt[i]);
}for(i=0;i<n;i++){
atat+=tat[i];
atat=atat/n;
awt=awt/n;
printf("\navgtat=%.2fandavgwt=%.2f",atat,awt);
return 0;
SLIP12
class Graph:
self.graph = graph
self.H = heuristicNodeList
self.start = startNode
self.parent = {}
self.status = {}
self.solutionGraph = {}
def applyAOStar(self):
self.aoStar(self.start, False)
def getNeighbors(self, v):
return self.status.get(v, 0)
self.status[v] = val
return self.H.get(n, 0)
self.H[n] = value
def printSolution(self):
print("FOR GRAPH SOLUTION, TRAVERSE THE GRAPH FROM THE START NODE:", self.start)
print("------------------------------------------------------------")
print(self.solutionGraph)
print("------------------------------------------------------------")
minimumCost = 0
costToChildNodeListDict = {}
costToChildNodeListDict[minimumCost] = []
flag = True
for nodeInfoTupleList in self.getNeighbors(v):
cost = 0
nodeList = []
cost = cost+self.getHeuristicNodeValue(c)+weight
nodeList.append(c)
if flag == True:
minimumCost = cost
costToChildNodeListDict[minimumCost] = nodeList
flag = False
else:
minimumCost = cost
costToChildNodeListDict[minimumCost] = nodeList
print("-----------------------------------------------------------------------------------------")
if self.getStatus(v) >= 0:
print(minimumCost, childNodeList)
self.setHeuristicNodeValue(v, minimumCost)
self.setStatus(v, len(childNodeList))
solved = True
for childNode in childNodeList:
self.parent[childNode] = v
if self.getStatus(childNode) != -1:
if solved == True:
self.setStatus(v, -1)
self.solutionGraph[v] = childNodeList
if v != self.start:
self.aoStar(self.parent[v], True)
if backTracking == False:
self.setStatus(childNode, 0)
self.aoStar(childNode, False)
print("Graph - 1")
graph1 = {
G1.applyAOStar()
G1.printSolution()
Q2) Write a simulation program using FCFS. The arrival time, CPU burst time and number of process
should be given as input to the system. The output should give the Turned around time and waiting
time for each process and calculate Average Waiting Time and Turned around Time. [20Marks]
wait_time[0] = 0;
return 0;
// burst_time[i] + wait_time[i]
int i;
return 0;
}
//Function to calculate average time
int i;
// around time
return 0;
// main function
int main() {
//process id's
avgtime(proc, n, burst_time);
return 0;
class Graph:
self.graph = graph
self.H = heuristicNodeList
self.start = startNode
self.parent = {}
self.status = {}
self.solutionGraph = {}
def applyAOStar(self):
self.aoStar(self.start, False)
return self.status.get(v, 0)
self.status[v] = val
return self.H.get(n, 0)
def setHeuristicNodeValue(self, n, value):
self.H[n] = value
def printSolution(self):
print("FOR GRAPH SOLUTION, TRAVERSE THE GRAPH FROM THE START NODE:", self.start)
print("------------------------------------------------------------")
print(self.solutionGraph)
print("------------------------------------------------------------")
minimumCost = 0
costToChildNodeListDict = {}
costToChildNodeListDict[minimumCost] = []
flag = True
cost = 0
nodeList = []
cost = cost+self.getHeuristicNodeValue(c)+weight
nodeList.append(c)
if flag == True:
minimumCost = cost
costToChildNodeListDict[minimumCost] = nodeList
flag = False
else:
minimumCost = cost
costToChildNodeListDict[minimumCost] = nodeList
print("-----------------------------------------------------------------------------------------")
if self.getStatus(v) >= 0:
print(minimumCost, childNodeList)
self.setHeuristicNodeValue(v, minimumCost)
self.setStatus(v, len(childNodeList))
solved = True
self.parent[childNode] = v
if self.getStatus(childNode) != -1:
if solved == True:
self.setStatus(v, -1)
self.solutionGraph[v] = childNodeList
if v != self.start:
self.aoStar(self.parent[v], True)
if backTracking == False:
self.aoStar(childNode, False)
print("Graph - 1")
graph1 = {
G1.applyAOStar()
G1.printSolution()
Q2) 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 as the number
of memory frames. Implement OPT Reference String : 12,15,12,18,6,8,11,12,19,12,6,8,12,15,19,8
[20Marks]
//OPT
#include<stdio.h>
int main()
int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1, flag2, flag3, i, j, k, pos, max,
faults = 0;
printf("Enter number of frames: ");
scanf("%d", &no_of_frames);
scanf("%d", &no_of_pages);
scanf("%d", &pages[i]);
frames[i] = -1;
flag1 = flag2 = 0;
if(frames[j] == pages[i]){
flag1 = flag2 = 1;
break;
if(flag1 == 0){
if(frames[j] == -1){
faults++;
frames[j] = pages[i];
flag2 = 1;
break;
if(flag2 == 0){
flag3 =0;
temp[j] = -1;
if(frames[j] == pages[k]){
temp[j] = k;
break;
if(temp[j] == -1){
pos = j;
flag3 = 1;
break;
}
if(flag3 ==0){
max = temp[0];
pos = 0;
max = temp[j];
pos = j;
frames[pos] = pages[i];
faults++;
printf("\n");
printf("%d\t", frames[j]);
return 0;
SLIP14
Q1) Given an initial state of a 8-puzzle problem and final state to be reached 2 8 3 1 6 4 7 5 1 2 3 8 4 7 6
5 Find the most cost-effective path to reach the final state from initial state using A* Algorithm.
Consider g(n)=Depth of node and h(n)=Number of misplaced tiles [10 Marks] .
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include<time.h>
#define r 3
#define c 3
char matrix[r][c];
char new[r][c];
int count;
int i,j;
char z ;
int p,q,x,y;
int t =0;
int result = 0;
void load()
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
if(new[i][j] == '0')
continue;
matrix[i][j]= new[i][j];
void blank()
for(i=0;i<3;i++)
for(j=0;j<3;j++)
int main()
time_t T= time(NULL);
struct tm tm = *localtime(&T);
char f[4];
int rsl ;
int random,t;
int randvalues[9];
main:
count = 0;
blank();
T= time(NULL);
tm = *localtime(&T);
srand(tm.tm_sec);
while(count!=9)
rsl=rand()%9;
sprintf(f,"%d",rsl);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if((new[i][j]) == f[0])
i = 4; j = 4;
continue;
new[i][j] = f[0];
i = 4; j = 4;
count++;
load();
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("|%c|",matrix[i][j]);
printf("\n");
while(1)
scanf(" %c",&z);
if(z=='q')
printf("\n*****You Quit*****\n");
goto main;
// break;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if((matrix[i][j])== z)
p = i;
q = j;
x = i;
y = j;
t =0;
int m , n ;
m = p - 1;
n=q;
if(m>=0)
{
if((matrix[m][n])== ' ')t=1;
m = p + 1;
if(m<=2)
m = p;
n=q-1;
if(n>=0)
n=q+1;
if(n<=2)
if(t==1)
matrix[x][y] = z;
t = 0;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if((matrix[i][j])== final[i][j])
t++;
system("clear");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("|%c|",matrix[i][j]);
printf("\n");
if(t==9)
printf("\n****you Win****\n");
break;
}
}
return 1;
Q2) 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 as the number of
memory frames. Implement FIFO Reference String: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 [20Marks]
//FIFO
#include <stdio.h>
int main()
int pageFaults = 0;
int frames = 3;
int m, n, s, pages;
pages = sizeof(incomingStream)/sizeof(incomingStream[0]);
int temp[frames];
temp[m] = -1;
s = 0;
if(incomingStream[m] == temp[n])
{
s++;
pageFaults--;
pageFaults++;
temp[m] = incomingStream[m];
else if(s == 0)
printf("\n");
printf("%d\t\t\t",incomingStream[m]);
if(temp[n] != -1)
else
printf(" - \t\t\t");
return 0;
SLIP15
Q1) Write a program to illustrate the concept of orphan process (Using fork () and sleep()) [10 Marks]
//FORK() SLEEP()
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
int main()
if(pid>0)
printf("Parent process\n");
else if(pid==0)
printf("Child process\n");
sleep(5);
else
return 0;
Q2) Write the simulation program for demand paging and show the page scheduling and total number
of page faults according to SECOND CHANCE page replacement algorithm. Assume the memory of 3
frames. Request Page Numbers: 9,14,10, 11, 15, 9, 11, 9, 15, 10, 9, 15, 10, 12, 15 [20Marks]
#include<stdio.h>
int refstring[20],pt[10],u[10],nof,nor;
void accept()
{
int i;
printf("\nEnter the reference string:");
for(i=0;i<nor;i++)
{
printf("[%d]=",i);
scanf("%d",&refstring[i]);
}
}
int search(int s)
{
int i;
for(i=0;i<nof;i++)
if(pt[i]==s)
return(i);
return(-1);
}
void second_chance()
{
int i,j,k,faults=0,sp=0;
for(i=0;i<nor;i++)
{
printf("%d",refstring[i]);
k=search(refstring[i]);
if(k==-1)
{
while(1)
{
if(u[sp]==0)
{
pt[sp]=refstring[i];
u[sp]=1;
sp=(sp+1)%nof;
faults++;
break;
}
else
{
u[sp]=0;
sp=(sp+1)%nof;
}
}
}
for(j=0;j<nof;j++)
{
printf("\n%3d%3d",pt[j],u[j]);
if(j==sp)
printf("*");
}
}
printf("\t");
printf("Total page faults=%d\n",faults);
}
int main()
{
clrscr();
printf("Enter length of reference string:");
scanf("%d",&nor);
printf("Enter the no. of frames:");
scanf("%d",&nof);
accept();
second_chance();
getch();
}