libc: Add support for pstat()

This commit is contained in:
apio 2022-10-22 14:26:42 +02:00
parent bcdcfc4b45
commit 6ac57a2f5c
4 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,36 @@
#ifndef _LUNA_PSTAT_H
#define _LUNA_PSTAT_H
#include <sys/types.h>
struct pstat
{
pid_t pt_pid;
pid_t pt_ppid;
char pt_name[128];
int pt_state;
pid_t pt_time;
};
#define PT_IDLE 0
#define PT_RUNNING 1
#define PT_SLEEPING 2
#define PT_ZOMBIE 3
#define PT_WAITING 4
#ifdef __cplusplus
extern "C"
{
#endif
/* Returns information about the process with PID pid in buf, if buf is non-null. Luna-specific. */
pid_t pstat(pid_t pid, struct pstat* buf);
/* Returns a string representation of the process state in buf. */
const char* pstname(struct pstat* buf);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -22,5 +22,6 @@
#define SYS_waitpid 18 #define SYS_waitpid 18
#define SYS_access 19 #define SYS_access 19
#define SYS_fstat 20 #define SYS_fstat 20
#define SYS_pstat 21
#endif #endif

View File

@ -0,0 +1,24 @@
#include <luna/pstat.h>
#include <sys/syscall.h>
#include <unistd.h>
extern "C"
{
pid_t pstat(pid_t pid, struct pstat* buf)
{
return syscall(SYS_pstat, pid, buf);
}
const char* pstname(struct pstat* buf)
{
switch (buf->pt_state)
{
case PT_IDLE: return "Idle";
case PT_RUNNING: return "Running";
case PT_SLEEPING: return "Sleeping";
case PT_WAITING: return "Waiting";
case PT_ZOMBIE: return "Zombie";
default: return "Unknown";
}
}
}

View File

@ -24,6 +24,7 @@ extern "C" long syscall(long number, ...)
case SYS_munmap: case SYS_munmap:
case SYS_access: case SYS_access:
case SYS_fstat: case SYS_fstat:
case SYS_pstat:
case SYS_open: { case SYS_open: {
arg arg0 = va_arg(ap, arg); arg arg0 = va_arg(ap, arg);
arg arg1 = va_arg(ap, arg); arg arg1 = va_arg(ap, arg);