| git.druid.rocks | index | druid520 | kaboom | src/ | user/ | ps.nsc |
src/user/ps.nsc
include "syscalls.nsh";
include "stdio.nsh";
/* "ps is literal ls /proc essentially" -- this is
* even more literal than that: /proc/ps (virtfs.nsc, kernel-side) is a
* real virtual file that's regenerated fresh on every read from
* exec.nsc's own process table (sh itself, plus whatever single
* command it's currently running -- see that file's own note on why
* that's the whole real process tree kaboom has), and this command is
* nothing but a hardcoded cat of it. */
global i32
main(i32 argc, ptr argv)
{
i8 buf[512];
i32 fd;
i64 n;
fd = sys_open("/proc/ps", (u64)8);
if(fd < 0)
{
print_err(2, "ps", "/proc/ps not found");
return 1;
}
n = sys_read(fd, &buf[0], (u64)512);
sys_close(fd);
if(n < (i64)0)
{
print_err(2, "ps", "read failed");
return 1;
}
sys_write(1, &buf[0], (u64)n);
return 0;
}