-#if ! defined BB_FEATURE_USE_DEVPS_N_DEVMTAB
-
-/* The following is the first ps implementation --
- * the one using the /proc virtual filesystem.
- */
-
-#if ! defined BB_FEATURE_USE_PROCFS
-#error Sorry, I depend on the /proc filesystem right now.
-#endif
-
-typedef struct proc_s {
- char
- cmd[16]; /* basename of executable file in call to exec(2) */
- int
- ruid, rgid, /* real only (sorry) */
- pid, /* process id */
- ppid; /* pid of parent process */
- char
- state; /* single-char code for process state (S=sleeping) */
-} proc_t;
-
-
-
-static int file2str(char *filename, char *ret, int cap)
-{
- int fd, num_read;
-
- if ((fd = open(filename, O_RDONLY, 0)) == -1)
- return -1;
- if ((num_read = read(fd, ret, cap - 1)) <= 0)
- return -1;
- ret[num_read] = 0;
- close(fd);
- return num_read;
-}
-
-
-static void parse_proc_status(char *S, proc_t * P)
-{
- char *tmp;
-
- memset(P->cmd, 0, sizeof P->cmd);
- sscanf(S, "Name:\t%15c", P->cmd);
- tmp = strchr(P->cmd, '\n');
- if (tmp)
- *tmp = '\0';
- tmp = strstr(S, "State");
- sscanf(tmp, "State:\t%c", &P->state);
-
- tmp = strstr(S, "Pid:");
- if (tmp)
- sscanf(tmp, "Pid:\t%d\n" "PPid:\t%d\n", &P->pid, &P->ppid);
- else
- fprintf(stderr, "Internal error!\n");
-
- /* For busybox, ignoring effective, saved, etc */
- tmp = strstr(S, "Uid:");
- if (tmp)
- sscanf(tmp, "Uid:\t%d", &P->ruid);
- else
- fprintf(stderr, "Internal error!\n");
-
- tmp = strstr(S, "Gid:");
- if (tmp)
- sscanf(tmp, "Gid:\t%d", &P->rgid);
- else
- fprintf(stderr, "Internal error!\n");