Implementation of PCB

Gift2011's Avatar, Join Date: Feb 2011
Newbie Member
Write an algorithm for implementing a Process Control Block
Gift2011's Avatar, Join Date: Feb 2011
Newbie Member
I tried this way:
Is just Algorithm you can not run it
Code:
//Pcb implementation using FCFS
/***************************************************
	last ----> ____
			  |pcb2|
			  |       |---> _____
			  |____|    |pcb1 |
			                |        | <---- first
			                |____ |
**************************************************/

struct pcb {
	int pid;
	int pc;
	float burstTime;
	.
	.	//Other attibutes of PCB
	.
	pcb *next;
};

class pcbQueue {
	private:
		pcb *last,*first;
	public:
		pcbQueue() //constractor
		{first=0;last=0}
		~pcbQueue() //Destructor
		void addProcess(pcb process)
		void executeProcess();
};

void pcbQueue::addProcess(pcb process){
	pcb *newpcb = new pcb;
	if(first == 0 && last== 0) // first process
		first=last=newpcb;
	newpcb->pid = process.pid;
	newpcb->pc  = process.pc;
	newpcb->burstTime  = process.burstTime;
	.
	.
	.
	newpcb->next=last;
	last = newpcb;	
}

/////////////////////////////////////////////////////////////////////////
void pcbQueue::executeProcess(){
	pcb *current = first; float time=0;
	if(first !=last){
		while(time < current->burstTime){
			execute(current); // execute the current process decrement burstTime
                        if(enterrupt_occur)
                           context_swiching(current);
			//after execution
			time = time+current->burstTime;
		}
	}
}

void main()
{
	pcbQueue fcfsqueue; boolean done = false;
	while(!done){
		//create three processes
		for(int i=0;i<3;i++){
		pcb newprocess = fork(); //create new process, assume fork return pcb of a new process.
			fcfsqueue.addProcess(newprocess);
		}
		//execute processes
		fcfsqueue.executeProcess();
		
	}	
}

Last edited by shabbir; 15Feb2011 at 07:17.. Reason: Code blocks