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

@@ -19,7 +19,7 @@ void task_start_first();
void task_switch_next(); void task_switch_next();
pid_t task_spawn(task_entrypoint, void *entry_data, char* name); pid_t task_spawn(task_entrypoint, void *entry_data, char *name);
void task_end(pid_t tid); void task_end(pid_t tid);
@@ -27,7 +27,7 @@ void task_suspend();
pid_t task_get_current_tid(); pid_t task_get_current_tid();
void task_signal(uint32_t tid); void task_signal(pid_t tid);
void task_lock_acquire(); void task_lock_acquire();
@@ -35,4 +35,6 @@ void task_ensure_enabled();
void task_lock_free(); void task_lock_free();
void task_print_all();
#endif //NEW_KERNEL_TASK_H #endif //NEW_KERNEL_TASK_H

View File

@@ -17,6 +17,7 @@
#include <myke/libk/libk.h> #include <myke/libk/libk.h>
#include <myke/mem/malloc.h> #include <myke/mem/malloc.h>
#include <myke/mem/mem.h> #include <myke/mem/mem.h>
#include <myke/tasks/task.h>
#include <myke/util/power.h> #include <myke/util/power.h>
#ifdef ENABLE_SELF_TEST #ifdef ENABLE_SELF_TEST
@@ -50,11 +51,13 @@ void help(const char *args);
void shutdown(const char *args); void shutdown(const char *args);
void ps(const char *args);
#ifdef ENABLE_SELF_TEST #ifdef ENABLE_SELF_TEST
void explode(const char *args); void explode(const char *args);
void kill_self(const char* args); void kill_self(const char *args);
void exec_self_test(const char *args); void exec_self_test(const char *args);
@@ -70,6 +73,7 @@ cmd_handler cmd_handlers[] = {
{"print", print}, {"print", print},
{"ide", ide}, {"ide", ide},
{"shutdown", shutdown}, {"shutdown", shutdown},
{"ps", ps},
#ifdef ENABLE_SELF_TEST #ifdef ENABLE_SELF_TEST
{"slingurl", slingurl}, {"slingurl", slingurl},
{"kill-self", kill_self}, {"kill-self", kill_self},
@@ -92,7 +96,7 @@ void smash(const char *args) {
memset(data, 'A', 32); memset(data, 'A', 32);
} }
void kill_self(const char* args) { void kill_self(const char *args) {
syscall_kill_self(); syscall_kill_self();
} }
@@ -115,6 +119,10 @@ void shutdown(const char *args) {
power_shutdown(); power_shutdown();
} }
void ps(const char *args) {
task_print_all();
}
void print_bootinfo() { void print_bootinfo() {
printf("Bootloader name: %s\n" printf("Bootloader name: %s\n"
"cmdline: %s\n", "cmdline: %s\n",

View File

@@ -12,7 +12,7 @@
#include <myke/libk/syscall.h> #include <myke/libk/syscall.h>
typedef struct lock_fifo_entry { typedef struct lock_fifo_entry {
uint32_t tid; pid_t tid;
struct lock_fifo_entry *next; struct lock_fifo_entry *next;
} lock_fifo_entry_t; } lock_fifo_entry_t;

View File

@@ -4,6 +4,7 @@
#include <attributes.h> #include <attributes.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -34,7 +35,7 @@ typedef struct task {
// identity // identity
pid_t tid; pid_t tid;
char* name; char *name;
// linked list // linked list
struct task *next; struct task *next;
@@ -72,7 +73,7 @@ extern att_cdecl att_noreturn void __task_entry_point();
extern att_noreturn void __task_entry_point_inner(); extern att_noreturn void __task_entry_point_inner();
// internal api // internal api
void task_free(task_t* task); void task_free(task_t *task);
// explicit cdecl calling convention // explicit cdecl calling convention
void att_unused att_cdecl att_noreturn task_entry_point(task_entrypoint entrypoint, void *entry_data) { 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; return current_task->tid;
} }
void task_signal(uint32_t tid) { void task_signal(pid_t tid) {
task_t *t = first_task; task_t *t = first_task;
while (t != NULL) { while (t != NULL) {
if (t->tid == tid) { if (t->tid == tid) {
@@ -243,7 +244,7 @@ void task_switch_next() {
task_switch_next_inner(task_first_runnable()); 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)); task_t *new_task = malloc(sizeof(task_t));
memset((uint8_t *) new_task, 0, sizeof(task_t)); memset((uint8_t *) new_task, 0, sizeof(task_t));
new_task->tid = last_tid++; new_task->tid = last_tid++;
@@ -289,7 +290,7 @@ void task_init() {
reaper_pid = task_spawn(task_reaper, NULL, "reaper"); 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); task_t *new_task = task_create(entrypoint, entry_data, name);
if (first_task == NULL) { if (first_task == NULL) {
// first task // first task
@@ -312,3 +313,16 @@ void task_end(pid_t tid) {
t = t->next; 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();
}