feat: added ps command
This commit is contained in:
@@ -19,7 +19,7 @@ void task_start_first();
|
||||
|
||||
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);
|
||||
|
||||
@@ -27,7 +27,7 @@ void task_suspend();
|
||||
|
||||
pid_t task_get_current_tid();
|
||||
|
||||
void task_signal(uint32_t tid);
|
||||
void task_signal(pid_t tid);
|
||||
|
||||
void task_lock_acquire();
|
||||
|
||||
@@ -35,4 +35,6 @@ void task_ensure_enabled();
|
||||
|
||||
void task_lock_free();
|
||||
|
||||
void task_print_all();
|
||||
|
||||
#endif //NEW_KERNEL_TASK_H
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <myke/libk/libk.h>
|
||||
#include <myke/mem/malloc.h>
|
||||
#include <myke/mem/mem.h>
|
||||
#include <myke/tasks/task.h>
|
||||
#include <myke/util/power.h>
|
||||
|
||||
#ifdef ENABLE_SELF_TEST
|
||||
@@ -50,11 +51,13 @@ void help(const char *args);
|
||||
|
||||
void shutdown(const char *args);
|
||||
|
||||
void ps(const char *args);
|
||||
|
||||
#ifdef ENABLE_SELF_TEST
|
||||
|
||||
void explode(const char *args);
|
||||
|
||||
void kill_self(const char* args);
|
||||
void kill_self(const char *args);
|
||||
|
||||
void exec_self_test(const char *args);
|
||||
|
||||
@@ -70,6 +73,7 @@ cmd_handler cmd_handlers[] = {
|
||||
{"print", print},
|
||||
{"ide", ide},
|
||||
{"shutdown", shutdown},
|
||||
{"ps", ps},
|
||||
#ifdef ENABLE_SELF_TEST
|
||||
{"slingurl", slingurl},
|
||||
{"kill-self", kill_self},
|
||||
@@ -92,7 +96,7 @@ void smash(const char *args) {
|
||||
memset(data, 'A', 32);
|
||||
}
|
||||
|
||||
void kill_self(const char* args) {
|
||||
void kill_self(const char *args) {
|
||||
syscall_kill_self();
|
||||
}
|
||||
|
||||
@@ -115,6 +119,10 @@ void shutdown(const char *args) {
|
||||
power_shutdown();
|
||||
}
|
||||
|
||||
void ps(const char *args) {
|
||||
task_print_all();
|
||||
}
|
||||
|
||||
void print_bootinfo() {
|
||||
printf("Bootloader name: %s\n"
|
||||
"cmdline: %s\n",
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <myke/libk/syscall.h>
|
||||
|
||||
typedef struct lock_fifo_entry {
|
||||
uint32_t tid;
|
||||
pid_t tid;
|
||||
struct lock_fifo_entry *next;
|
||||
} lock_fifo_entry_t;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user