计算机与信息
学院 实验课程:操作系统
阜阳师范学院 Fuyang Teachers College
实验报告 ====================================================================
姓名 学号:
实验报告
实验报告
实验报告
}
exit(0);
}
main( )
{ client( );
}
2.server.c
#include <sys/types.h>
#include <sys/msg.h>
#include <sys/ipc.h>
#define MSGKEY 75
struct msgform
{ long mtype;
char mtext[1000];
}msg;
int msgqid;
void server( )
{
msgqid=msgget(MSGKEY,0777|IPC_CREAT); do
{
msgrcv(msgqid,&msg,1030,0,0);
printf(“(server)received\n”);
}while(msg.mtype!=1);
msgctl(msgqid,IPC_RMID,0);
exit(0);
}
main( )
{
server( );
}
实验报告
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 12
#define B 3
#define P 5
int isInBuf(int buf[], int x, int *p)
{ int i, j = -1;
for (i = 0; i < B; i++)
{ if(buf[i] == x)
{ j = i;
break;
}
else if (buf[i] == -1)
{ (*p)++;
buf[i] = x;
j = i;
break;
}
}
if(j==-1) (*p)++;
return j;
}
int oldopt(int i, int buf[ ], int list[ ], int f[ ]) { int k, h, j=0, max=-1;
for (k = 0; k < B; k++)
{ for (h = i; h < N; h++)
if (buf[k] == list[h])
{ f[k] = h;
break;
}
if(h==N)
f[k] = N;
}
for (k = 0; k < B; k++)
{ if (max < f[k])
{ max = f[k];
j = k;
}
}
return j;
}
int main()
{ int list[N]; #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 12
#define B 3
#define P 5
int isInBuf(int buf[], int x, int *p) { int i, j = -1;
for (i = 0; i < B; i++)
{ if(buf[i] == x)
{ j = i;
break;
}
else if (buf[i] == -1)
{ (*p)++;
buf[i] = x;
j = i;
break;
}
}
if(j==-1) (*p)++;
return j;
}
int oldlru(int f[ ])
{ int i, j = 0, max = -1;
for (i = 0; i < B; i++)
{ if(f[i] > max)
{ max = f[i];
j = i;
}
f[i]++;
}
return j;
}
int main()
{ int list[N];
int change[N];
int buf[B], f[B], i, j,k;
int result[B][N];
int old;
int absent;
srand((int)time(NULL));
printf("\n The Random List:\n");
for (i = 0; i < N; i++)
int change[N];
int buf[B],f[B],i,j,k;
int result[B][N];
int old;
int absent;
srand((int)time(NULL));
printf("\n The Random List:\n");
for (i = 0; i < N; i++)
{ list[i] = rand() % P+1;
printf("%3d", list[i]);
}
printf("\n----------------------------------------------\n");
printf("\nOPT:\n");
absent=0;
for(i = 0; i < B; i++)
buf[i] = f[i] = -1;
for(i = 0; i < N; i++)
{ j=isInBuf(buf, list[i],&absent);
if(j== -1) //需置换页面
{ old=oldopt(i, buf, list, f);
change[i]=buf[old];
buf[old] = list[i];
}
else change[i]=-1;
for(k=0;k<B;k++)
result[k][i]=buf[k];
}
printf("the result is:\n");
for(i=0;i<B;i++)
{ for(j=0;j<N;j++)
printf("%3d",result[i][j]);
printf("\n");
}
printf("\nthe page is changed:\n");
for(i=0;i<N;i++)
{ if(change[i]== -1)
printf(" ");
else printf("%3d",change[i]);
}
printf("\nabsent:%d\n",absent);
printf("the absent vote is:%f\n",(float)absent/N);}
{ list[i] = rand() % P+1;
printf("%3d", list[i]);
}
printf("\n-------------------------------------------\n");
printf("\nLRU:\n");
absent = 0;
for(i = 0; i < B; i++)
buf[i] = f[i] = -1;
for(i = 0; i < N; i++)
{ j = isInBuf(buf, list[i],&absent);
old = oldlru(f);
if(j== -1)
{ change[i]=buf[old];
buf[old] = list[i];
f[old] = 0;
}
else
{ f[j]=0;
change[i]=-1;
}
for(k=0;k<B; k++)
result[k][i]=buf[k];
}
printf("the result is:\n");
for(i=0;i<B;i++)
{ for(j=0;j<N;j++)
printf("%3d",result[i][j]);
printf("\n");
}
printf("\nthe page is changed:\n");
for(i=0;i<N;i++)
{ if(change[i]== -1)
printf(" ");
else
printf("%3d",change[i]);
}
printf("\nabsent:%d\n",absent);
printf("the absent vote is:%f\n",(float)absent/N); }
实验报告。