Operating system experiment -- paging storage management

Keywords: Algorithm data structure Operating System

2, Paging memory management

catalogue

2.1 purpose

2.2 contents

2.3 experimental tips

2.4 data structure

2.5 algorithm design and flow chart  

2.6 operation screenshot

2.7 summary

2.8 code

2.1 purpose

  1. Master the basic principle of paging management, and reflect the process of memory space allocation, recovery and address conversion in the experimental process.
  2. Master the use of bit diagram to manage the allocation and recovery of memory and replacement space.
  3. Master basic bit operation
  4. Master the basic principle of request paging storage management, and experience the allocation and recovery of memory and replacement space, address conversion and page missing processing during the experiment.

2.2 contents

On the basis of Experiment 1, the process of paging storage management, memory allocation and address translation is realized. Further implement the request paging storage management process, including memory and replacement space management, address translation and page missing processing, which can reflect the idea of FIFO and LRU algorithm.

2.3 experimental tips

1. Establish a bit diagram data structure to simulate memory usage. Bit diagram is a data structure that uses the 0 / 1 value of several bits to represent the occupied state of a certain kind of space. In this experiment, the number of bits of the bit diagram is the same as the set number of physical blocks. When the program is started, a group of random 0 or 1 can be used to fill the bit diagram to simulate that the memory has been occupied when the program starts to execute.

Assuming that the memory size is 64K and the block size is 1K, there are 64 blocks in total. The following bit diagram data structure needs to be created:

#define BLOCK_SIZE 1024 / / block size, which is defined as a macro for easy modification

#define MEM_SIZE 64 / / number of blocks

//Define a char type array. Each char variable occupies 8 bits, with a length of 8 and a total of 64 bits

char bitmap[MEM_SIZE/8];

The codes filled randomly are as follows:

#include "time.h"

...

srand(time(NULL));

for(i=0;i<MEM_SIZE/8;i++)

...bitmap[i]=(char)rand();

The possible values of the bit diagram after random filling are shown in Figure 2-1. This bit diagram shows that blocks such as 2 (bit 2 of 0 byte), 3 (bit 3 of 0 byte), 6 (bit 6 of 0 byte), 8 (bit 0 of 1 byte), 9 (bit 1 of 1 byte), 12 (Bit 4 of 1 byte), 15 (bit 7 of 1 byte)... Of memory are not occupied.

 

Figure 2-1 example of bit diagram with random value

2. Expand PCB Based on Experiment 1 and add process size and page table:

struct PCB{

...

int size;

int* page_table;

When creating a process, enter the process size, allocate page table space for the process according to the page size set in the program, and allocate physical blocks. For example, based on the above figure, if you want to establish a process with a size of 5000 bytes, then

  1. Calculate that the process has a total of "rounding up (5000 / 1024) = 5" pages, which needs to occupy 5 memory blocks;
  2. Create an empty page table, that is, a one-dimensional integer array with length of 5;
  3. Find out the position numbers of the first five "0" bits in the whole bit diagram (i.e. the free block number in the memory) (if the j bit of the i-th byte is 0, the position of this bit in the bit diagram is 8*i+j), fill these position numbers in the page table in turn, and change the corresponding "0" to "1" to show that the corresponding memory block has been allocated.

tmp=(struct PCB *)malloc(sizeof(struct PCB));// PCB of the created process

tmp->size=size;// Process size

//Calculate the number of blocks

block_ count=(int)ceil(tmp->size/(double)BLOCK_SIZE);  // Allocation page table

tmp->page_table=(int *)malloc(sizeof(int)*block_count);

Determine the bit of a byte b in the bit diagram_ Whether the no bit is 1 or 0, the code is as follows:

int getbit(char b,int bit_no){   

   // Move 00000001 left bit_no bit to obtain the value such as 00010000

   char mask=(char)1<<bit_no;

    If (B & mask) / / if the result after the and operation is not 0, then the bit_ The no bit must be 1

      return 1;

    else / / if the result of the and operation is 0, then the bit_ The no bit must be 0

      return 0;

}

Set the bit of a byte b of the bit diagram_ The no bit is 1 or 0, and the code is as follows:

void setbit(char *b,int bit_no,int flag){

    char mask=(char)1<<bit_ no;// Get the value such as 00010000

    if(flag)//flag is true, it means that bit_ The no bit is set to 1

      * b=*b|mask;// Or operation, the corresponding bit becomes 1

    else{//flag is false, indicating that the bit_no bit is set to 0

       mask=~mask; / / take the inverse to get the value such as 11101111

      * B = * B & mask; / / perform the and operation, and the corresponding bit becomes 0

   }

}

3. Enter the logical address to be accessed by the current execution process and convert it into the corresponding physical address:

(1) First, write the boundary value between the page number and the address in the logical address according to the page size (if the page size is 1024, the boundary value is log21024=10)

int mylog2(int size){//size is the page size    

   return (int)ceil((log10(size)/log10(2)));

}

(2) Calculate the page number and in page address according to the entered logical address la:

int la,pageno,offset,mask;

printf("logical address: (< 0 exit)");

scanf("%d",&la);

//Move the logical address to the right several bits to get the page number

pageno=la>>mylog2(BLOCK_SIZE);

//Move 1111... 111 left several bits to obtain 11... 11000.. 00

mask=(0xffffffff)<<mylog2(BLOCK_SIZE);

//Reverse 11... 11000.. 00 to get 00... 00111.. 11

mask=~mask;

//And operate the logical address with the mask to obtain the address in the page

offset=la&mask;

  1. When the process exits, backfill "1" at the corresponding position of the bit diagram to "0" according to its page table content.
  2. Expand the page table and turn it into a two-dimensional page table supporting request and replacement functions (add existence bits, etc.). When creating a process, you can load the first three fixed pages (or enter the initial number of pages loaded by keyboard, and the number of pages loaded by different processes can be different), and the rest pages can be loaded into the replacement space (the displacement space size shall be 1.5-2 times of the memory space size, and an independent displacement space bit diagram shall be established for it).
  3. FIFO or LRU replacement algorithms are used to replace the page missing phenomenon that may be encountered in the process of address conversion. The page numbers involved in multiple address conversion can be regarded as the page access sequence of the process, so as to calculate the replacement times and page missing rate. The following is an interactive example in the process of address conversion (red is user input and blue is program prompt):

Logical address: 3072

Write instruction (Y/N):Y

The page number corresponding to the logical address 3072 is: 3, and the intra page offset address is: 0

Page 3 is not in memory. The external memory block number is 12. It needs to be replaced

    Select Page 1 of memory by FIFO algorithm. The memory block number of this page is 6, the modification bit is 1, and the external memory block number is 10

    Write the contents of block 6 of the memory to block 10 of the external memory successfully

    Transfer the contents of block 12 of external memory into block 6 of memory, and the replacement is completed

The physical address corresponding to the logical address 3072 is 6144

2.4 data structure

Structure, linked list, one-dimensional array

2.5 algorithm design and flow chart  

2.6 operation screenshot

 

2.7 summary

The function is basically realized. The debugging is successful without warning or error.

Through experiments, we have a better understanding of the basic process of page replacement algorithm and can solve related problems

2.8 code

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
#define block_size 1024 / / block size
#define mem_size 64 / / memory size
#define swapspace_size 128 / / displacement space size
#define lode_count 3 / / the maximum number of pages loaded by the process
#define maxsize 10 / / maximum page table space
int bitmap[64];
int swapbitmap[128];
using namespace std;
typedef struct Page_table//Page table
{
	int pageno,blockno,swapspaceno;//Page number, block number, replacement block number
	int exists;//Presence bit,
}page_table[maxsize];
typedef struct PCB
{
	int name;
	int sizes;    //Process size
	page_table pt;//Page table of a process
	int length;//Number of current page tables
	int fifo[3],lru[3],opt[3];
	int optlist[maxsize];
	int fifon,lrun,listn;//Number of pages in FIFO and LRU
	double absent1,absent2,absent3;
	double visit1,visit2;
	struct PCB *next;
}PCB,*PCBlist;
PCBlist running;
void createbitmap()//Create bit view
{
	int i;
	srand(time(NULL));
	for(i=0;i<mem_size;i++)
		bitmap[i]=(rand()%2);
    for(i=0;i<swapspace_size;i++)
		swapbitmap[i]=(rand()%2);
}
void showbitmap()//Display bit view
{
	cout<<"Position diagram"<<endl;
	int i;
	for(i=0;i<mem_size;i++)
	{
		cout<<bitmap[i];
		if((i+1)%8==0)
			cout<<endl;
	}
	cout<<"Displacement space diagram"<<endl;
	for(i=0;i<swapspace_size;i++)
	{
		cout<<swapbitmap[i];
		if((i+1)%16==0)
			cout<<endl;
	}
}
void initpagetable(PCBlist &s)//Initialize page table
{
     PCBlist p;
    p=s->next;
	int i,j;
        for(i=0;i<maxsize;i++)
        {
            p->pt[i].pageno=-1;
            p->pt[i].blockno=-1;
            p->pt[i].swapspaceno=-1;
            p->pt[i].exists=0;
        }
        for(j=0;j<lode_count;j++)
        {
            p->fifo[j]=-1;
            p->lru[j]=-1;
            p->opt[j]=-1;
        }
}
void createpage(PCBlist &s)//Create page table
{
    PCBlist p;
    p=s->next;
	int m;
	int i,j=0,k=0,t=0;
	m= (int)ceil((double)p->sizes/(double)block_size);
	p->length=m;
	p->listn=p->fifon=p->lrun=0;
	p->absent1=p->absent2=p->absent3=0;
	p->visit1=p->visit2=0;
	if(m<=lode_count)
	{
		for(i=0;i<m;i++)//Memory, page table assignment
		{
			while((bitmap[j]!=0))//Find free memory in bit diagram
			{
				j++;
			}
			bitmap[j]=1;
			p->pt[i].pageno=i;
			p->pt[i].blockno=j;//j record location
			p->pt[i].exists=1;
		}
		cout<<"The page table of the process is as follows:"<<endl;
		cout<<"Page number\t\t Block number\t\t Existential bit\t\t Replacement block number"<<endl;
		for(i=0;i<m;i++)//Page table display
		{
			cout<<p->pt[i].pageno<<'\t'<<'\t';
			cout<<p->pt[i].blockno<<'\t'<<'\t';
			cout<<p->pt[i].exists<<'\t'<<'\t';
			cout<<p->pt[i].swapspaceno;
			cout<<endl;
		}

	}
	else
	{
		for(i=0;i<lode_count;i++)
		{
			while(bitmap[k]!=0)//Find free memory in bit diagram
			{
				k++;
			}
			bitmap[k]=1;//Modify bit diagram
			p->pt[i].pageno=i;
			p->pt[i].blockno=k;
			p->pt[i].exists=1;
		}
		cout<<"The page table of the process is as follows:"<<endl;
		cout<<"Page number\t\t Block number\t\t Existential bit\t\t Replacement block number"<<endl;
		for(i=0;i<lode_count;i++)
		{
			cout<<p->pt[i].pageno<<'\t'<<'\t';
			cout<<p->pt[i].blockno<<'\t'<<'\t';
			cout<<p->pt[i].exists<<'\t'<<'\t';
			cout<<p->pt[i].swapspaceno;
			cout<<endl;
		}
		for(i=lode_count;i<m;i++)//Store pages that are not in memory in replacement space
		{
			while(swapbitmap[t]!=0)//t is the external memory block number and i is the page number
			{
				t++;
			}
			swapbitmap[t]=1;
			p->pt[i].swapspaceno=t;
			p->pt[i].pageno=i;
		}
		cout<<"The page table of the process in the replacement space is as follows:"<<endl;
		cout<<"Page number\t\t Block number\t\t Existential bit\t\t Replacement block number"<<endl;
		for(i=lode_count;i<m;i++)
		{
			cout<<p->pt[i].pageno<<'\t'<<'\t';
			cout<<p->pt[i].blockno<<'\t'<<'\t';
			cout<<p->pt[i].exists<<'\t'<<'\t';
			cout<<p->pt[i].swapspaceno;
			cout<<endl;
		}
	}
}
void operateadress(PCBlist s)//Calculate physical address
{
    PCBlist p;
    p=s->next;
	cout<<"Enter logical address"<<endl;
	int a,b,c,d;
	cin>>a;
	b=a/block_size;//Calculate page number
	c=a%block_size;//Calculate in page offset
	d=p->length;
	if(b>d-1)//Is the page number greater than the page table length
        cout<<"An out of bounds error occurred during this interrupt\n";
    else
    {
        if(b>=lode_count)
        {
            cout<<"Not in memory"<<endl;
            cout<<"The address is:"<<(p->pt[b].swapspaceno)*(block_size)+c<<'\t'<<"The block number is "<<p->pt[b].swapspaceno<<"number"<<'\t'<<'\t'<<"In the first"<<(p->pt[b].swapspaceno)/8<<"that 's ok"<<'\t'<<"The first"<<(p->pt[b].swapspaceno)%8<<"column"<<'\t'<<"Offset is"<<c<<endl;
        }
        else
        {
             cout<<"In memory"<<endl;
             cout<<"The address is:"<<(p->pt[b].blockno)*(block_size)+c<<'\t'<<"The block number is"<<p->pt[b].blockno<<"number"<<'\t'<<'\t'<<"In the first"<<(p->pt[b].blockno)/8<<"that 's ok"<<'\t'<<"The first"<<(p->pt[b].blockno)%8<<"column"<<'\t'<<"Offset is"<<c<<endl;
        }
    }

}

void pcbover(PCBlist s)
{
    PCBlist p;
    p=s->next;
	cout<<"Bit diagram after process end"<<endl;
	int i,j;
	for(i=0;i<3;i++)
	{
		if(p->pt[i].blockno>=0)
			bitmap[p->pt[i].blockno]=0;
	}
	for(j=3;j<=p->length;j++)
	{
		if(p->pt[j].swapspaceno>=0)
			swapbitmap[p->pt[j].swapspaceno]=0;
	}
	showbitmap();
}
int findplace(int x,PCBlist p)//Find the position of the page in the page table
{
    int i;
    for(i=0;i<=p->length;i++)
        if(p->pt[i].pageno==x)
        return i;
    return -1;
}


void FIFO(PCBlist s)
{

    PCBlist p;
    p=s->next;
	int i,j,k,a,b,c,d,x,y,z,temp1,temp2;
	p->visit1++;
	cout<<"Please enter a logical address"<<endl;
	cin>>a;
	b=a/block_size;//Page number
    /*for(c=0;c<=p->length;i++)
        if(p->pt[c].pageno==b)
            break;*/
	c=findplace(b,p);//Find the position of the page number in the page table
	p->optlist[p->listn]=b;//Store the page in the total page sequence to prepare for opt
	p->listn++;
	if(a>p->sizes)
        cout<<"An out of bounds error occurred"<<endl;
    else
    {
        for(i=0;i<3;i++)
            if(b==p->fifo[i])
                break;
        z=i;
		if(z!=3)//Page in queue
        {
            cout<<"No page missing"<<endl;
            for(i=0;i<3;i++)
            {
                if(p->fifo[i]!=-1)
                    cout<<p->fifo[i]<<" ";
            }

            cout<<endl;
        }
		else
		{   p->absent1++;
			if(p->fifon<3)//The queue is not full
			{
				if(p->pt[c].exists==1)//The missing page is in memory
                {
                    p->fifo[p->fifon]=p->pt[c].pageno;
                    for(k=0;k<3;k++)
                    {
                        if(p->fifo[k]!=-1)
                            cout<<p->fifo[k]<<" ";
                    }
                    (p->fifon)++;
                    cout<<endl;
                }
                else
                {
                    for(j=0;j<lode_count;j++)//Look for pages that are not in the queue as pages to be exchanged;
                        if(  (p->pt[j].pageno!=p->fifo[0])&&(p->pt[j].pageno!=p->fifo[1])&&(p->pt[j].pageno!=p->fifo[3]))
                        break;
                    d=j;
                    p->fifo[p->fifon]=p->pt[c].pageno;
                    temp1=p->pt[d].pageno;//Exchange page number
                    p->pt[d].pageno=p->pt[c].pageno;
                    p->pt[c].pageno=temp1;
                    for(k=0;k<3;k++)
                    {
                        if(p->fifo[k]!=-1)
                            cout<<p->fifo[k]<<" ";
                    }

                    (p->fifon)++;
                    cout<<endl;
                    cout<<"There is no page in memory, transferred from external memory. "<<endl;
                }
			}
			else//The queue is full
            {
                if(p->pt[c].exists==1)
                {
                    p->fifo[0]=p->fifo[1];
                    p->fifo[1]=p->fifo[2];
                    p->fifo[2]=p->pt[c].pageno;
                    for(k=0;k<3;k++)
                    {
                        if(p->fifo[k]!=-1)
                            cout<<p->fifo[k]<<" ";
                    }
                    cout<<endl;
                }
                else
                {
                    x=p->fifo[0];
                    p->fifo[0]=p->fifo[1];
                    p->fifo[1]=p->fifo[2];
                    p->fifo[2]=p->pt[c].pageno;
                    y=findplace(x,p);
                    temp2=p->pt[y].pageno;
                    p->pt[y].pageno=p->pt[c].pageno;
                    p->pt[c].pageno=temp2;
                    for(k=0;k<3;k++)
                    {
                        if(p->fifo[k]!=-1)
                            cout<<p->fifo[k]<<" ";
                    }
                    cout<<endl;
                    cout<<"There is no page in memory, transferred from external memory. "<<endl;
                }
            }
		}
    }
    cout<<"The replacement times are:"<<p->absent1<<"second   "<<" The page missing rate is:"<<(p->absent1/p->visit1)*100<<"%"<<endl;
}
void LRU(PCBlist s)
{
    PCBlist p;
    p=s->next;
    int i,j,k,a,b,c,d,x,y,z,m,temp1,temp2,temp3,l;//a is the address entered, and l determines whether there is an element subscript in the queue
	p->visit2++;
	cout<<"Please enter a logical address"<<endl;
	cin>>a;
	b=a/block_size;//Page number
	c=findplace(b,p);//Find the position of the page number in the page table
	p->optlist[p->listn]=b;//Store the page in the total page sequence to prepare for opt
	p->listn++;
	if(a>=p->sizes)
        cout<<"An out of bounds error occurred"<<endl;
    else
    {
        for(l=0;l<3;l++)//Does lru queue have this number
            if(b==p->lru[l])
                break;
        z=l;//cout<<z<<endl;
		if(z!=3)//Page in queue
        {
            cout<<"No page missing"<<endl;
            temp1=p->lru[z];//temp1 is the element that exists
            if(p->lrun<=2)
			{
				p->lru[z]=p->lru[p->lrun-1];
				p->lru[p->lrun-1]=temp1;

            }
           else
		   {
				for(m=z;m<3;m++)
				  p->lru[m]=p->lru[m+1];
				p->lru[2]=temp1;
            }
           for(i=0;i<3;i++)
           {
                if(p->lru[i]!=-1)
                    cout<<p->lru[i]<<" ";
           }

            cout<<endl;
      }
		else//No longer in queue
		{   p->absent2++;//Replacement times + 1;
			if(p->lrun<3)//The queue is not full
			{
				if(p->pt[c].exists==1)//The missing page is in memory
                {
                    p->lru[p->lrun]=p->pt[c].pageno;
                    for(k=0;k<3;k++)//display
                    {
                        if(p->lru[k]!=-1)
                            cout<<p->lru[k]<<" ";
                    }
                    (p->lrun)++;
                    cout<<endl;
                }
                else//In external memory
                {
                    for(j=0;j<lode_count;j++)//Find the first empty physical fast in the queue;
                        if((p->pt[j].pageno!=p->lru[0])&&(p->pt[j].pageno!=p->lru[1])&&(p->pt[j].pageno!=p->lru[2]))
                        break;
                    d=j;
                    p->lru[p->lrun]=p->pt[c].pageno;
                    temp2=p->pt[d].pageno;//Exchange page number
                    p->pt[d].pageno=p->pt[c].pageno;
                    p->pt[c].pageno=temp2;
                    for(k=0;k<3;k++)
                    {
                        if(p->lru[k]!=-1)
                            cout<<p->lru[k]<<" ";
                    }

                    (p->lrun)++;
                    cout<<endl;
                    cout<<"There is no page in memory, transferred from external memory. "<<endl;
                }
			}
			else//The queue is full
            {
                if(p->pt[c].exists==1)
                {
                    p->lru[0]=p->lru[1];
                    p->lru[1]=p->lru[2];
                    p->lru[2]=p->pt[c].pageno;
                    for(k=0;k<3;k++)
                    {
                        if(p->lru[k]!=-1)
                            cout<<p->lru[k]<<" ";
                    }
                    (p->lrun)++;
                    cout<<endl;
                }
                else
                {
                    x=p->lru[0];
                    p->lru[0]=p->lru[1];
                    p->lru[1]=p->lru[2];
                    p->lru[2]=p->pt[c].pageno;
                    y=findplace(x,p);
                    temp3=p->pt[y].pageno;
                    p->pt[y].pageno=p->pt[c].pageno;
                    p->pt[c].pageno=temp3;
                    for(k=0;k<3;k++)
                    {
                        if(p->lru[k]!=-1)
                            cout<<p->lru[k]<<" ";
                    }
                    (p->lrun)++;
                    cout<<endl;
                    cout<<"There is no page in memory, transferred from external memory. "<<endl;
                }
            }
		}
    }
     cout<<"The replacement times are:"<<p->absent2<<"second   "<<" The page missing rate is:"<<(p->absent2/p->visit2)*100<<"%"<<endl;
}
void out(PCBlist p)
{
  while(p->next!=NULL)
    {
       cout<<p->next->name<<" ";
       cout<<p->next->sizes<<" ";
       p=p->next;
    }
  cout<<"\n";
}
void show(PCBlist p)//Ready status and blocked status display
{
    while(p->next)
	{
		cout<<p->next->name<<" ";
		p=p->next;
	}
}
void runshow(int m)//Execution status display
{
	if(m==0)
		cout<<"There are no processes in progress"<<endl;
	else
		cout<<m<<endl;
}
void add(PCBlist &l,int name,int sizes)
{
	PCBlist p=l;
	PCBlist s=new PCB;
	s->name=name;
	s->sizes=sizes;
	s->next=NULL;
	if(p->next==NULL)//Add node when process chain is empty
	{
		p->next=s;
	}
	else
	{
		while(p->next!=NULL)//Process chain is not empty. Add node
		{
			p=p->next;
		}
		p->next=s;
	}
}
void showall(PCBlist p1,PCBlist p2,int m)//Process status display
{
	cout<<"Ready status is:";
	show(p1);
	cout<<endl;
	cout<<"Execution status is:";
	runshow(m);
	cout<<"Blocking status is:";
	show(p2);
	cout<<endl;
}
int main()
{
	int n,number,c,m=0,j=0,sizes,temp;//m label the executing process n menu, select number process name, sizes process size, c wake up the process
	PCBlist ready=new PCB;
	ready->next=NULL;
    PCBlist blocked=new PCB;
	blocked->next=NULL;
    running=new PCB;
	running->next=NULL;
	PCBlist pa=ready,pb=blocked,pc=ready,pd=blocked;
	PCBlist p,q;
	while(true)
	{
	    cout<<"Welcome to my paged storage management system"<<endl;
	    cout<<"1-Create process"<<endl;
        cout<<"2-Time slice to"<<endl;
        cout<<"3-Process blocking"<<endl;
        cout<<"4-Wake up process"<<endl;
        cout<<"5-End process"<<endl;
        cout<<"6-create a bitmap"<<endl;
        cout<<"7-Create and display a page table for the process"<<endl;
        cout<<"8-display bitmap"<<endl;
        cout<<"9-Address transformation"<<endl;
        cout<<"10-LRU algorithm"<<endl;
        cout<<"11-FIFO algorithm"<<endl;
        cout<<"13-Display execution process information"<<endl;
        cout<<"0-sign out"<<endl;
        cout<<"Please enter the serial number according to the function"<<endl;
        cin>>n;
		switch(n)
		{
		case 1://Create process
			 {
                cout<<"Please enter the process name(With 0~9 express):";
                cin>>number;
                cout<<"Please enter the process size:";
                cin>>sizes;
				add(ready,number,sizes);
				if(m==0)//If there is no process in progress
				{
					if(ready->next!=NULL)//Ready queue is not empty
					{
					    add(running,ready->next->name,ready->next->sizes);
						temp=ready->next->name;//Get queue head process (first element of ready queue)
						ready->next=ready->next->next;//Change ready state to execution state
						m=temp;
					}
					showall(ready,blocked,m);
				}
				else
				{
					showall(ready,blocked,m);
				}
				break;
			}
		case 2://Time slice to
			{
				if(m!=0)
				{
					add(ready,m,running->next->sizes);//Add the executing process to the ready state
					m=0;running->next=NULL;
					if(ready->next!=NULL)
					{
					    //running->next=ready->next;
					    add(running,ready->next->name,ready->next->sizes);
						temp=ready->next->name;
						ready->next=ready->next->next;
						m=temp;
					}//Change the queue head of the ready queue to the execution state at this time
					showall(ready,blocked,m);
				}
				else
				{
					cout<<"There are no processes in progress"<<endl;
				}
				break;
			}
		case 3://Process blocking
			{
				if(m==0)
					cout<<"There are no processes in progress"<<endl;
				else
				{
					add(blocked,m,running->next->sizes);//Add blocked processes to the blocking queue
					m=0;running->next=NULL;
					if(ready->next!=NULL)
					{
					    add(running,ready->next->name,ready->next->sizes);
						temp=ready->next->name;
						ready->next=ready->next->next;
						m=temp;
					}//Change the queue head of the ready queue to the execution state at this time
					showall(ready,blocked,m);
				}
				break;
			}
		case 4://Wake up process
			{
				if(blocked->next==NULL)
					cout<<"There are no blocking processes"<<endl;
				else
				{
					cout<<"Please enter the process to wake up"<<endl;
					cin>>c;
					while(pb->next->name!=c)//Find the process to wake up
						pb=pb->next;
					add(ready,pb->next->name,pb->next->sizes);//Add the process to wake up to the ready queue
					if(pb->next->next!=NULL)
					    pb->next=pb->next->next;
					else
                        pb->next=NULL;
					//showall(ready,blocked,m);
				}
				if(m==0)//If there is no process in progress
				{
					if(ready->next!=NULL)
					{
					    add(running,ready->next->name,ready->next->sizes);
						temp=ready->next->name;
						m=temp;
						ready->next=ready->next->next;
					}
					showall(ready,blocked,m);

				}
				else{
					showall(ready,blocked,m);
				}
				break;
			}
		case 5://End process
			{
			       pcbover(running);
					m=0;running->next=NULL;
					if(ready->next!=NULL)
					{
					    add(running,ready->next->name,ready->next->sizes);
					    //out(ready);
						temp=ready->next->name;
						ready->next=ready->next->next;
						m=temp;
					}
					showall(ready,blocked,m);
				break;
			}
         case 6:createbitmap();showbitmap();break;

         case 7:
             {
                 initpagetable(running);
                 p=running->next;
                 if(p->pt[0].pageno!=-1)
                    cout<<"Page table created"<<endl;
                 else
                 {
                     initpagetable(running);
                     createpage(running); break;
                 }
                 break;
             }
         case 8:showbitmap();break;

         case 9:operateadress(running);break;

         case 10:LRU(running);break;

         case 11:FIFO(running);break;

         case 13:out(running);
             break;

         case 0:exit(0);
		}
	}
	return 0;
}

Posted by neuroxik on Tue, 12 Oct 2021 15:39:21 -0700