diff options
author | dzwdz | 2023-09-22 23:42:30 +0200 |
---|---|---|
committer | dzwdz | 2023-09-22 23:42:30 +0200 |
commit | 6a4d4a41a664e6a4c406a449ea847abd4a224bcf (patch) | |
tree | 0a637697c8697929beb8f4b7ff69d8b74f9e28bb /src/cmd/ps | |
parent | a3d6aa9f8d427b86a33dc05bed98a2e88229a285 (diff) |
build: support single file commands
Diffstat (limited to 'src/cmd/ps')
-rw-r--r-- | src/cmd/ps/ps.c | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/cmd/ps/ps.c b/src/cmd/ps/ps.c deleted file mode 100644 index c855251..0000000 --- a/src/cmd/ps/ps.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <_proc.h> -#include <ctype.h> -#include <dirent.h> -#include <err.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -void -usage(void) -{ - fprintf(stderr, "usage: ps [path]\n"); - exit(1); -} - -int -main(int argc, const char *argv[]) -{ - const char *path = argc >= 2 ? argv[1] : "/proc/"; - if (argc > 2) usage(); - - char *procbuf = malloc(4096); - DIR *dir = opendir(path); - if (!dir) { - err(1, "couldn't open %s", path); - } - - struct dirent *de; - while ((de = readdir(dir))) { - const char *name = de->d_name; - if (isdigit(name[0])) { - FILE *g; - sprintf(procbuf, "%s%smem", path, name); - 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); - } - *strchr(name, '/') = '\0'; - printf("%s\t%s\n", name, procbuf); - } - } - - free(procbuf); - closedir(dir); - return 0; -} |