Exemple #1
0
/*
 Destroys Process with Process ID by clearing the struct
 Calls free_PCB to do this
 @return 1 if freed properly
 @return 0 if failed
 */
uint32_t process_destroy(int PID)
{
	uint32_t* addressToClear = get_address_of_PCB(PID);
	pcb* pcb_p = get_PCB(PID);
	uint32_t free_success = free_PCB(pcb_p);
	*addressToClear = 0; //clears the pointer to the PCB

	if (free_success)
	{
		return 1;
	}
	else
	{
		return 0;
	}

}
/*
 * Decrement the remaining CPU time from a process. If the process has no
 * remaining CPU time, then the process will be terminated.
 *
 * The parameters for this function are pointers to pointers of a struct so that
 * the underlying pointer can be changed by this function.
 *
 * PARAMETERS
 *     pcb: Pointer to the PCB to alter.
 *
 * RETURN VALUE
 * A pointer to the same process, unless this process was terminated in which
 * case NULL is returned.
 */
PCB * decrement_remaining_cpu_time(PCB ** pcb) {
    if (*pcb != NULL) {
        // Decrement the remaining CPU time for the process and check whether the process has any remaining CPU time
        if ((--((*pcb)->remaining_cpu_time)) <= 0) {
            // Time's up - terminate process
            *pcb = terminate_PCB(pcb);

            // Free memory associated with the PCB
            free_PCB(pcb);

            // The PCB has been freed, return NULL
            return NULL;
        }
    }

    // Return the PCB
    return *pcb;
}
Exemple #3
0
// removes process from memory
void terminateProcess(int argc, char *argv[]){

	if (argc == 2){ // checks for args then searches for process
		char name[STRLEN];
		PCB *pointer;
		strcpy(name,argv[1]);
		pointer = find_PCB(name);
	
		if ( pointer != NULL){
			remove_PCB(pointer);
			free_PCB(pointer);
		}
	}
	
	else{
		printf("Wrong arguments entered.");
		return;
	}
}