diff options
author | dzwdz | 2023-08-14 18:51:07 +0200 |
---|---|---|
committer | dzwdz | 2023-08-14 18:51:07 +0200 |
commit | 642b5fb0007b64c77d186fcb018d571152ee1d47 (patch) | |
tree | 1c466461f3602d306be309a053edae558ef2568e /src/user/app/ps | |
parent | 8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff) |
reorganization: first steps
Diffstat (limited to 'src/user/app/ps')
-rw-r--r-- | src/user/app/ps/ps.c | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/user/app/ps/ps.c b/src/user/app/ps/ps.c deleted file mode 100644 index 76a5841..0000000 --- a/src/user/app/ps/ps.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <_proc.h> -#include <ctype.h> -#include <err.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -int -main(void) -{ - char *readbuf = malloc(4096); - char *procbuf = malloc(4096); - FILE *f = fopen("/proc/", "r"); - if (!f) { - err(1, "couldn't open /proc/"); - } - - // TODO library for iterating over directories - for (;;) { - int len = fread(readbuf, 1, 4096, f); - if (len <= 0) break; - for (int pos = 0; pos < len; ) { - char *end = memchr(readbuf + pos, 0, len - pos); - if (!end) { - errx(1, "unimplemented: buffer overflow"); - } - size_t entryl = end - (readbuf+pos) + 1; - if (isdigit(readbuf[pos])) { - FILE *g; - sprintf(procbuf, "/proc/%smem", readbuf+pos); - g = fopen(procbuf, "r"); - if (!g) { - warn("couldn't open \"%s\"", procbuf); - strcpy(procbuf, "(can't peek)"); - } else { - fseek(g, (long)&_psdata_loc->desc, SEEK_SET); - if (fread(procbuf, 1, 128, g) <= 0) { - strcpy(procbuf, "(no psdata)"); - } - procbuf[128] = '\0'; - fclose(g); - } - end[-1] = '\0'; /* remove trailing slash */ - printf("%s\t%s\n", readbuf+pos, procbuf); - } - pos += entryl; - } - } - - free(readbuf); - free(procbuf); - fclose(f); - return 0; -} |