summaryrefslogtreecommitdiff
path: root/src/sys/os
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-10-11 13:40:09 -0400
committerIan Moffett <ian@osmora.org>2025-10-11 13:40:09 -0400
commit73cd54a1f5fbdefbafff9227f5d00feb86b4199e (patch)
tree476024f30be7c401b06a3c825dfb7217f908ea5a /src/sys/os
parent15b856bec1cbe233bcdcdf2712c646c73d87f9f5 (diff)
kern: proc: Add process lookups by PID
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys/os')
-rw-r--r--src/sys/os/os_proc.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/sys/os/os_proc.c b/src/sys/os/os_proc.c
index 4af45a0..decb41e 100644
--- a/src/sys/os/os_proc.c
+++ b/src/sys/os/os_proc.c
@@ -35,6 +35,7 @@
#include <sys/syslog.h>
#include <sys/panic.h>
#include <sys/proc.h>
+#include <sys/queue.h>
#include <sys/cpuvar.h>
#include <os/systm.h>
#include <vm/vm.h>
@@ -44,7 +45,17 @@
#include <os/kalloc.h>
#include <os/filedesc.h>
#include <string.h>
+#include <stdbool.h>
+/*
+ * System-wide process state
+ *
+ * XXX: The process queue here is different from the runqueues,
+ * these keep track of the processes present whether they
+ * are running or not (unless terminated)
+ */
+static bool is_procq_init = false;
+static TAILQ_HEAD(, proc) procq;
static pid_t next_pid = 0;
/*
@@ -171,6 +182,12 @@ proc_init(struct proc *procp, int flags)
return -EINVAL;
}
+ /* Initialize the process queue once */
+ if (!is_procq_init) {
+ TAILQ_INIT(&procq);
+ is_procq_init = true;
+ }
+
/* Put the process in a known state */
scdp = &procp->scdom;
memset(procp, 0, sizeof(*procp));
@@ -197,7 +214,33 @@ proc_init(struct proc *procp, int flags)
}
error = fdtab_init(procp);
- return error;
+ if (error != 0) {
+ return error;
+ }
+
+ TAILQ_INSERT_TAIL(&procq, procp, link);
+ return 0;
+}
+
+/*
+ * Lookup a process by PID
+ */
+struct proc *
+proc_lookup(pid_t pid)
+{
+ struct proc *curproc;
+
+ TAILQ_FOREACH(curproc, &procq, link) {
+ if (curproc == NULL) {
+ continue;
+ }
+
+ if (curproc->pid == pid) {
+ return curproc;
+ }
+ }
+
+ return NULL;
}
/*
@@ -237,6 +280,7 @@ proc_kill(struct proc *procp, int status)
procp->flags |= PROC_EXITING;
proc_clear_ranges(procp);
+ TAILQ_REMOVE(&procq, procp, link);
return md_proc_kill(procp, 0);
}