Exemplo n.º 1
0
void suspendPCB(char PCBName[20]){
	PCB *process;
	int sus;//suspended
	int sta;//state
	process = findPCB(PCBName); //find PCB
	if(process==NULL){
		print("Error: PCB not found");	
	}
	else{//if found PCB
	//check sus state
		sus = (process->suspended);
		sta = (process->state);
		if(sus==0){//if PCB is not suspended 
		
			if((sta==0)){ //if state is blocked
			
				removePCB(process);//remove from blockedQueue
				process->suspended = 1;//change state to suspended
				insertPCB(process);//insert into suspendedBlockedQueue

			}
			else if((sta==2)){
				removePCB(process);//remove from readyQueue
				process->suspended = 1;//change state to suspended
				insertPCB(process);//insert into suspendedReadyQueue

			}
			else if(sta==1){//if state is running		
				print("Error: PCB is running");		
			}
			else{//if state is invalid
				print("Error: PCB state is invalid");
			}
		}
		else if(sus==1){
			print("Error: Process is already suspended");
		}
		else{
			print("Error: Suspended state invalid");
		}
	}
}
Exemplo n.º 2
0
void loadComHandler(){
 PCB *thePCB;
 context *con;

 thePCB = setupPCB("ComHandler",127,SYS);
 thePCB->state= READY;
 con=(context*)thePCB->stackTop;
 con->IP = FP_OFF(&prompt);
 con->CS = FP_SEG(&prompt);
 con->FLAGS = 0x200;
 con->DS = _DS;
 con->ES = _ES;
 insertPCB(thePCB);
}
Exemplo n.º 3
0
void setPCBpriority(char PCBName[20], int inputPriority){
	PCB *process = findPCB(PCBName); //find PCB
	if((inputPriority < -128) || (inputPriority > 127)){ 
		//if incorrect input priority
		print("Error: Invalid Priority: Must be between -128 and +127\n");
	}
	else if(process==NULL){
		print("Error: PCB not found\n");
	}
	else{ 
		removePCB(process);
		process -> priority = inputPriority;
		insertPCB(process);
		
	}
}
Exemplo n.º 4
0
void setPriority()
{
	serial_print("Please enter the name of the process to alter: ");
	char* name = polling();
	PCB *target = findPCB(name);
	if(target == NULL)
	{
		serial_print("Process not found: \"");
		serial_print(name);
		serial_println("\" is not a valid process name");
	}
	else
	{
		serial_print("What is the new priority? ");
		char* newPriority = polling();
		int priority = atoi(newPriority);
		if(-1 < priority && 10 > priority)
		{
			target->priority = priority;
			int readyIndex = indexByNameReady(name);
			int blockedIndex = indexByNameBlocked(name);
			if (readyIndex >= 0) {
				removePCBAtIndexReady(readyIndex);
			} else {
				removePCBAtIndexBlocked(blockedIndex);
			}
			insertPCB(target);
			serial_print("The process \"");
			serial_print(name);
			serial_println("\" has successfully updated its priority");
		}
		else
		{
			serial_println("Cannot set priority: invalid range");
		}
		sys_free_mem(newPriority);
	}
	sys_free_mem(name);
	sys_free_mem(target);
	serial_println("");
}
Exemplo n.º 5
0
void IOScheduler(){
	if(param_ptr->device_id==TERMINAL||param_ptr->device_id==COM_PORT){
		IOD *Descriptor = sys_alloc_mem(sizeof(IOD));
		Descriptor->ppt = COP;
		strcpy(Descriptor->PCBName,COP->processName);
		Descriptor->buffer = param_ptr->buf_addr;
		Descriptor->count = param_ptr->count_addr;
		Descriptor->requestType = param_ptr->op_code;
		if(param_ptr->device_id==TERMINAL){
			if(TerminalQueue-> count == 0){
				TerminalQueue->head = Descriptor;
				TerminalQueue->tail = Descriptor;
				TerminalQueue->count = 1;
				ProcessIORequest(1);
			}else{
				TerminalQueue->tail->next = Descriptor;
				TerminalQueue->tail = TerminalQueue->tail->next;
				TerminalQueue->count++;
			}
		}else if(param_ptr->device_id==COM_PORT){
			if(Com_PortQueue-> count == 0){
				Com_PortQueue->head = Descriptor;
				Com_PortQueue->tail = Descriptor;
				Com_PortQueue->count = 1;
				ProcessIORequest(2);
			}else{
				Com_PortQueue->tail->next = Descriptor;
				Com_PortQueue->tail = Com_PortQueue->tail->next;
				Com_PortQueue->count++;
			}
		}
		COP->state = 0;
		insertPCB(COP);
		//blockPCB(COP->processName);
	}
}