kernel/sys/process.c
/**
 * @brief Remove a process from the valid process list.
 *
 * Deletes a process from both the valid list and the process tree.
 * Any the process has any children, they become orphaned and are
 * moved under 'init', which is awoken if it was blocked on 'waitpid'.
 *
 * Finally, the process is freed.
 */
@brief Remove a process from the valid process list.
Deletes a process from both the valid list and the process tree.
Any the process has any children, they become orphaned and are
moved under 'init', which is awoken if it was blocked on 'waitpid'.

Finally, the process is freed.
@brief Remove a process from the valid process list . Deletes a process from both the valid list and the process tree . Any the process has any children they become orphaned and are moved under ' init ' which is awoken if it was blocked on ' waitpid ' . Finally the process is freed .
void process_delete(process_t * proc) {
	assert(proc != this_core->current_process);
	tree_node_t * entry = proc->tree_entry;
	if (!entry) {
		printf("Tried to delete process with no tree entry?\n");
		return;
	}
	if (process_tree->root == entry) {
		printf("Tried to delete process init...\n");
		return;
	}
	spin_lock(tree_lock);
	int has_children = entry->children->length;
	tree_remove_reparent_root(process_tree, entry);
	list_delete(process_list, list_find(process_list, proc));
	spin_unlock(tree_lock);
	if (has_children) {
		process_t * init = process_tree->root->value;
		wakeup_queue(init->wait_queue);
	}
	proc->tree_entry = NULL;
	shm_release_all(proc);
	free(proc->shm_mappings);
	if (proc->supplementary_group_list) {
		proc->supplementary_group_count = 0;
		free(proc->supplementary_group_list);
	}
	for (int i = 0; i < processor_count; ++i) {
		if (i == this_core->cpu_id) continue;
		if (processor_local_data[i].previous_process == proc ||
		    processor_local_data[i].current_process == proc) {
			process_reap_later(proc);
			return;
		}
	}
	process_reap(proc);
}
void process_delete ( process_t * proc ) { assert ( proc != this_core -> current_process ) ; tree_node_t * entry = proc -> tree_entry ; if ( ! entry ) { printf ( " \n " ) ; return ; } if ( process_tree -> root == entry ) { printf ( " \n " ) ; return ; } spin_lock ( tree_lock ) ; int has_children = entry -> children -> length ; tree_remove_reparent_root ( process_tree , entry ) ; list_delete ( process_list , list_find ( process_list , proc ) ) ; spin_unlock ( tree_lock ) ; if ( has_children ) { process_t * init = process_tree -> root -> value ; wakeup_queue ( init -> wait_queue ) ; } proc -> tree_entry = NULL ; shm_release_all ( proc ) ; free ( proc -> shm_mappings ) ; if ( proc -> supplementary_group_list ) { proc -> supplementary_group_count = 0 ; free ( proc -> supplementary_group_list ) ; } for ( int i = 0 ; i < processor_count ; ++ i ) { if ( i == this_core -> cpu_id ) continue ; if ( processor_local_data [ i ] . previous_process == proc || processor_local_data [ i ] . current_process == proc ) { process_reap_later ( proc ) ; return ; } } process_reap ( proc ) ; }
@brief Remove a process from the valid process list.
@brief Remove a process from the valid process list .
/* Wake up init */ // FIXME bitset_clear(&pid_set, proc->id); /* Is someone using this process? */