feat: added ps command

This commit is contained in:
2021-08-12 20:31:11 +02:00
parent 94c6332e27
commit 3034a5d417
4 changed files with 34 additions and 10 deletions

View File

@@ -4,6 +4,7 @@
#include <attributes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -34,7 +35,7 @@ typedef struct task {
// identity
pid_t tid;
char* name;
char *name;
// linked list
struct task *next;
@@ -72,7 +73,7 @@ extern att_cdecl att_noreturn void __task_entry_point();
extern att_noreturn void __task_entry_point_inner();
// internal api
void task_free(task_t* task);
void task_free(task_t *task);
// explicit cdecl calling convention
void att_unused att_cdecl att_noreturn task_entry_point(task_entrypoint entrypoint, void *entry_data) {
@@ -103,7 +104,7 @@ pid_t task_get_current_tid() {
return current_task->tid;
}
void task_signal(uint32_t tid) {
void task_signal(pid_t tid) {
task_t *t = first_task;
while (t != NULL) {
if (t->tid == tid) {
@@ -243,7 +244,7 @@ void task_switch_next() {
task_switch_next_inner(task_first_runnable());
}
task_t *task_create(task_entrypoint entrypoint, void *entry_data, char* name) {
task_t *task_create(task_entrypoint entrypoint, void *entry_data, char *name) {
task_t *new_task = malloc(sizeof(task_t));
memset((uint8_t *) new_task, 0, sizeof(task_t));
new_task->tid = last_tid++;
@@ -289,7 +290,7 @@ void task_init() {
reaper_pid = task_spawn(task_reaper, NULL, "reaper");
}
pid_t task_spawn(task_entrypoint entrypoint, void *entry_data, char* name) {
pid_t task_spawn(task_entrypoint entrypoint, void *entry_data, char *name) {
task_t *new_task = task_create(entrypoint, entry_data, name);
if (first_task == NULL) {
// first task
@@ -312,3 +313,16 @@ void task_end(pid_t tid) {
t = t->next;
}
}
void task_print_all() {
// acquiring task lock as reference to current task may disappear
// might overrun kprint buffer
task_lock_acquire();
printf("tasks:\n");
task_t *c = first_task;
while (c != NULL) {
printf("%d - %s\n", c->tid, c->name);
c = c->next;
}
task_lock_free();
}