Process Management
#include "stdafx.h"
#include <iostream>
using namespace std;
class Process
{
private:
int state, pid;
public:
Process()
{
state=0;
pid=100;
}
Process(int s, int p):state(s),pid(p){}
void New()
{
state=0;
cout<<"Process is
in state: "<<state;
cout<<"Process is
being created \n resource are being initialized \n";
for(int i=0; i<100; i++)
cout<<".";
cout<<"Process is
created and about to load\n";
ready();
}
void ready()
{
state=1;
cout<<"Process is
in state: "<<state;
cout<<"Process is
in main memory and waiting for cpu \n";
for(int i=0; i<100; i++)
cout<<".";
cout<<"\n Process
is about to dispatch \n";
running();
}
void running()
{
state=2;
cout<<"Process is
in state: "<<state;
cout<<"Process is
in cpu and instruction are being executed \n";
for(int i=0; i<100; i++)
cout<<".";
char choice;
cout<<"\n Press i
for interupt, w for waiting, and t for termination \n";
cin>>choice;
switch (choice)
{
case'i':
cout<<"Process
is interupted \n";
ready();
break;
case'w':
cout<<"Process
need I/O or event \n";
waiting();
break;
case't':
cout<<"Process
is about to finish \n";
terminate();
break;
default:
cout<<"Wrong
choice \n";
terminate();
}
}
void waiting()
{
state=3;
cout<<"Process is
in state: "<<state;
cout<<"Process is
in waiting queue and needs service \n";
for(int i=0; i<100; i++)
cout<<".";
cout<<"\n Process
is serviced \n";
ready();
}
void terminate()
{
state=4;
cout<<"Process is
in state: "<<state;
cout<<"\n Resoyrce
are being deallocated \n";
for(int i=0; i<100; i++)
cout<<".";
cout<<"\n Process
terminated Successfully \n";
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Process myprocess;
myprocess.New();
return 0;
}
No comments:
Post a Comment
Thank you very much for your nice Comments.