aboutsummaryrefslogtreecommitdiff
path: root/kernel/proc/proc.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-02-11 07:36:50 +0000
committersotech117 <michael_foiani@brown.edu>2024-02-11 07:36:50 +0000
commit6cfe0ddd014597113e0635fcdecba9db0cc2c64b (patch)
treeb40bbeda9f1e7ca44c1d59e75b94ed168310a959 /kernel/proc/proc.c
parentc71b9e406a8fb7bfcaeb20ee787d6eb4a1cbb71d (diff)
basic implementation of most functions. not tested, but generally well thought out
Diffstat (limited to 'kernel/proc/proc.c')
-rw-r--r--kernel/proc/proc.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/kernel/proc/proc.c b/kernel/proc/proc.c
index 6155b58..fd253f6 100644
--- a/kernel/proc/proc.c
+++ b/kernel/proc/proc.c
@@ -340,7 +340,7 @@ void proc_kill_all()
}
}
- // kill the current proc
+ // kill this proc
do_exit(0);
}
@@ -416,7 +416,58 @@ void proc_destroy(proc_t *proc)
*/
pid_t do_waitpid(pid_t pid, int *status, int options)
{
- NOT_YET_IMPLEMENTED("PROCS: do_waitpid");
+ // NOT_YET_IMPLEMENTED("PROCS: do_waitpid");
+
+ if (pid == 0 || options != 0 || pid < -1)
+ {
+ return -ENOTSUP;
+ }
+
+ if (pid > 0)
+ {
+ proc_t *child = proc_lookup(pid);
+ if (child == NULL || child->p_pproc != curproc)
+ {
+ return -ECHILD;
+ }
+
+ // sleep until this specific child process exits
+ while (child->p_state != PROC_DEAD)
+ {
+ sched_sleep_on(&curproc->p_wait);
+ }
+
+ if (status != NULL)
+ {
+ *status = child->p_status;
+ }
+ proc_destroy(child);
+
+ return pid;
+ }
+ else if (pid == -1)
+ {
+ if (list_empty(&curproc->p_children))
+ {
+ return -ECHILD;
+ }
+
+ proc_t *child;
+ list_iterate(&curproc->p_children, child, proc_t, p_child_link)
+ {
+ if (child->p_state == PROC_DEAD)
+ {
+ if (status != NULL)
+ {
+ *status = child->p_status;
+ }
+
+ proc_destroy(child);
+ return child->p_pid;
+ }
+ }
+ }
+
return 0;
}
@@ -425,7 +476,9 @@ pid_t do_waitpid(pid_t pid, int *status, int options)
*/
void do_exit(long status)
{
- NOT_YET_IMPLEMENTED("PROCS: do_exit");
+ // NOT_YET_IMPLEMENTED("PROCS: do_exit");
+
+ kthread_exit((void *)status);
}
/*==========