From d2b13e08f8d6111b7f7e79a47a124fc47dd9433c Mon Sep 17 00:00:00 2001 From: sotech117 Date: Tue, 20 Feb 2024 18:23:50 +0000 Subject: make tests and fix bugs that the tests caught :) --- kernel/proc/kthread.c | 2 +- kernel/proc/proc.c | 16 +++++++++------- kernel/proc/sched.c | 1 - 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'kernel/proc') diff --git a/kernel/proc/kthread.c b/kernel/proc/kthread.c index 42beb77..46dd627 100644 --- a/kernel/proc/kthread.c +++ b/kernel/proc/kthread.c @@ -99,7 +99,7 @@ kthread_t *kthread_create(proc_t *proc, kthread_func_t func, long arg1, list_init(&new_thread->kt_mutexes); new_thread->kt_recent_core = 0; - dbg(DBG_THR, "SUCCESFULLY created a new thread with proc name=%s, id=%d\n", proc->p_name, proc->p_pid); + dbg(DBG_THR, "SUCCESFULLY created a new THREAD with proc name=%s, id=%d\n", proc->p_name, proc->p_pid); return new_thread; } diff --git a/kernel/proc/proc.c b/kernel/proc/proc.c index 2a7cdba..d0566ec 100644 --- a/kernel/proc/proc.c +++ b/kernel/proc/proc.c @@ -181,8 +181,6 @@ proc_t *proc_create(const char *name) return NULL; } - dbg(DBG_PROC, "creating process name=%s & pid =%d\n", name, proc_pid); - proc_t *proc = (proc_t *)slab_obj_alloc(proc_allocator); if (proc == NULL) { @@ -219,6 +217,8 @@ proc_t *proc_create(const char *name) list_insert_tail(&curproc->p_children, &proc->p_child_link); list_insert_tail(&proc_list, &proc->p_list_link); + dbg(DBG_PROC, "SUCESSFULLY created PROCESS name=%s & pid =%d\n", name, proc_pid); + return proc; } @@ -325,12 +325,11 @@ void proc_kill_all() { // NOT_YET_IMPLEMENTED("PROCS: proc_kill_all"); - // TODO: consider children on children - list_iterate(&proc_initproc->p_children, thr, kthread_t, kt_plink) + list_iterate(&proc_list, p, proc_t, p_list_link) { - if((proc_t *) &thr->kt_proc != curproc) + if (p->p_pid != curproc->p_pid && p->p_pid != PID_IDLE) { - kthread_cancel(thr, 0); + proc_kill(p, 0); } } @@ -435,8 +434,10 @@ pid_t do_waitpid(pid_t pid, int *status, int options) if (status != NULL) { + dbg(DBG_PROC, "setting status to %d\n", child->p_status); *status = child->p_status; } + list_remove(&child->p_child_link); proc_destroy(child); dbg(DBG_PROC, "exited child pid=%d\n", child->p_pid); @@ -459,6 +460,7 @@ pid_t do_waitpid(pid_t pid, int *status, int options) dbg(DBG_PROC, "found a dead thread with pid=%d\n", child->p_pid); if (status != NULL) { + dbg(DBG_PROC, "setting status to %d\n", child->p_status); *status = child->p_status; } int child_pid = child->p_pid; @@ -487,7 +489,7 @@ void do_exit(long status) { // NOT_YET_IMPLEMENTED("PROCS: do_exit"); - dbg(DBG_PROC, "proc exiting with pid=%d", curproc->p_pid); + dbg(DBG_PROC, "proc exiting with pid=%d and status=%ld\n", curproc->p_pid, status); kthread_exit((void *)status); } diff --git a/kernel/proc/sched.c b/kernel/proc/sched.c index 0461279..cd8e438 100644 --- a/kernel/proc/sched.c +++ b/kernel/proc/sched.c @@ -243,7 +243,6 @@ void sched_switch(ktqueue_t *queue) intr_enable(); intr_setipl(oldIPL); - // TODO: ask about why we need the old thread context } /* -- cgit v1.2.3-70-g09d2