Esempio n. 1
0
void resume(){

	char *tempPtr = NULL;											//Temporary Input Character Pointer
	PCBitem *tempPCB;												//Temporary PCB Item
	int charCount = 0;	
	
	// Get PCB name from the user
	printf("Please enter the name of the PCB to resume: ");
	tempPtr = keyboardInput(0);										//Gets process name from User
	tempPtr = pointer2Str(tempPtr);									//Convert Character Pointer to Character String
	charCount = sizeOfPointer(tempPtr);								//Get Name Size
	
	if((charCount >= 8)){											//Check that Name is Valid (Check to see if at least 8 chars. + Null Terminator)
		tempPCB = find_PCB(tempPtr);
		if(tempPCB != NULL){										//Check if Name Exists
			if(tempPCB->state == RUNNING){
				printf("Error: There is no need to resume an already running process.\n");
			} else if(tempPCB->state == READY){
				printf("Error: This process is READY but not suspended.\n");
			} else if(tempPCB->state == BLOCKED){
				printf("Error: This process is Blocked but not suspended.\n");
			} else{
			
				// Should remove the process from the SUSREADY or SUSBLOCKED queue (by calling remove_PCB)
				error = remove_PCB(tempPCB->state, tempPCB);
				error = errorCheck(error);
				
				// Puts the PCB in the unsuspended state
				if(tempPCB->state == SUSREADY){
					tempPCB->state = READY;
				} else if(tempPCB->state == SUSBLOCKED){
					tempPCB->state = BLOCKED;
				}//end if
	
			    // Might require changing queues (from ready to suspended ready, for example) if 4 queues are used
				error = insert_PCB(tempPCB->state, tempPCB);
				error = errorCheck(error);
				
				// Display appropriate error or success message
				if(error == 0){
					printf("The PCB Process has been successfully resumed.\n");
				}//end if
			}//end if
		}else{
			printf("Process Name does not exist.\n");
		}//end if
	}else{
		printf("Process Name is Invalid. Process Name must be at least 8 characters in length.\n");
	}//end if
}//end resume
Esempio n. 2
0
void setPriority(){
	char *tempPtr = NULL;											//Temporary Input Character Pointer for PCB Name
	char *tempPtr2 = NULL;											//Temporary Input Character Pointer for New Priority
	PCBitem *tempPCB;												//Temporary PCB Item
	int charCount = 0;												//Number of Characters in Process Name
	int newPriority = 0;											//New Priority value
	
	//Get PCB name
	printf("Please enter the name of the PCB to Set the Priority: ");
	tempPtr = keyboardInput(0);										//Gets process name from User
	tempPtr = pointer2Str(tempPtr);									//Convert Character Pointer to Character String
	charCount = sizeOfPointer(tempPtr);								//Get Name Size
	
	
	if((charCount >= 8)){											//Check that the Name is Valid (Check to see if at least 8 chars. + Null Terminator)
		tempPCB = find_PCB(tempPtr);
		if(tempPCB != NULL){										//Check that the PCB Exists
			
			//Get New Priority from User
			printf("Please enter a number between -128 & +127 to set the new Priority: ");
			tempPtr = keyboardInput(0);									//Gets process name from User
			newPriority = pointer2Int(tempPtr);							//Convert Character Pointer to Int
			
			
			if((new_pPriority >= -128) || (new_pPriority <= 127)){		//Check that the new priority is valid (-128 to 127)
				tempPCB->pPriority = new_pPriority;						//Set new PCB Priority
				
				//If the PCB is in the ready state, you will need to change the position of the PCB in the queue based upon its new priority
				if(tempPCB->state == READY){
					error = remove_PCB(tempPCB->state, tempPCB);						//Remove PCB from Ready Queue
					error = errorCheck(error);							//Perform Error Check
					error = insert_PCB(tempPCB->state, tempPCB);						//Insert PCB into Ready Queue (so as to adjust for new Priority)
					error = errorCheck(error);							//Perform Error Check
				}//end if
			}//end if
			
			//Display appropriate error or success message.
			if(error == 0){
				printf("The PCB Process has been successfully blocked.\n");
			}//end if
			
		} else{
			printf("Process Name does not exist.\n");
		}//end if
	} else{
		printf("Process Name is Invalid. Process Name must be at least 8 characters in length.\n");
	}//end if
}//end setPriority
Esempio n. 3
0
// loads a program into memory
void loadProgram(int argc, char *argv[]){ //name,fileName,priority,path
	
	// sets up variables
	static int count;
	MEMDSC *tempMem;
	unsigned char temptop;
	char *dir, *name, *filename;
	int size,offset,priority;
	tcontext *tempContext;
	unsigned int *tempCS,*tempIP;
	STACKDSC *temp;
	
	// initializes values
	int err = 0;
	PCB *newPCB = allocate_PCB();
	tempMem=newPCB->memdsc;
	dir = (char*) sys_alloc_mem(30 * sizeof(char));
	name = (char*) sys_alloc_mem(30 * sizeof(char));
	filename = (char*) sys_alloc_mem(30 * sizeof(char));
	strcpy(dir,argv[4]);
	strcpy(name,argv[1]);
	strcpy(filename,argv[2]);
	priority = atoi(argv[3]);
	
	err = sys_check_program(dir,filename,&size,&offset); 
	
	if((argc==5)||(127<=priority<=-128)&&( err==0)){ //checks for validity
		
		

	      /*	if( count == ZERO ){ //If first process allocate queue
			rQueue = (ROOT*) sys_alloc_mem(sizeof(ROOT));
			wsQueue = (ROOT*) sys_alloc_mem(sizeof(ROOT));
		}   */

		setup_PCB(newPCB,name,APPLICATION,SUSPENDED_READY,priority);


		// sets up the adressess
		newPCB->memdsc->loadADDR= sys_alloc_mem(size);
		newPCB->memdsc->execADDR=newPCB->memdsc->loadADDR + offset;// is this the correct address? 

		
		//make sure all registers are properly set
		
		newPCB -> stackdsc-> top = newPCB -> stackdsc-> base + STACKSIZE - sizeof(tcontext);
		
		tempContext = (tcontext *) (newPCB -> stackdsc-> top);
		tempContext ->ES = _ES;
		tempContext ->DS = _DS;
		tempContext ->CS = FP_SEG(newPCB->memdsc->execADDR);
		tempContext ->IP = FP_OFF(newPCB->memdsc->execADDR);
		tempContext ->FLAGS = 0x200;
		
		// load the program into memory
		 err = sys_load_program(newPCB->memdsc->loadADDR,size,dir,filename);
		
		insert_PCB(newPCB);	// put pcb into a queue
		count++;//Update the number of times the function has run.
		
	}
	else{
		printf("Wrong or invalid arguments entered.");
	}
}