diff options
Diffstat (limited to 'package/sash/src/cmd_uclinux.c')
-rw-r--r-- | package/sash/src/cmd_uclinux.c | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/package/sash/src/cmd_uclinux.c b/package/sash/src/cmd_uclinux.c index 32886ebe4..bca2152b9 100644 --- a/package/sash/src/cmd_uclinux.c +++ b/package/sash/src/cmd_uclinux.c @@ -1,4 +1,3 @@ - #include "sash.h" #include <fcntl.h> @@ -29,37 +28,37 @@ do_ps(argc, argv) DIR * d; struct dirent * de; int l; - + printf(" PID TTY STAT TIME COMMAND\n"); - - + + d = opendir("/proc"); if (!d) return; - + while (de = readdir(d)) { for(i=0;i<strlen(de->d_name);i++) if (!isdigit(de->d_name[i])) goto next; - + sprintf(psbuf, "/proc/%s/stat", de->d_name); h = open(psbuf, O_RDONLY); - + if (h==-1) continue; - + l = read(h, psbuf, 255); if (l<=0) { perror("Unable to read status"); close(h); continue; } - + psbuf[l] = '\0'; psbuf[255] = '\0'; - - - if (sscanf(psbuf, + + + if (sscanf(psbuf, "%d %s %c", &pid, name, &statec)<3) { @@ -67,34 +66,34 @@ do_ps(argc, argv) close(h); continue; } - + state = statec; - + close(h); - + sprintf(psbuf, "/proc/%s/cmdline", de->d_name); h = open(psbuf, O_RDONLY); - + if (h == -1) { perror("Unable to open cmdline"); continue; } - + l = read(h, psbuf, 255); if (l < 0) { perror("Unable to read cmdline"); close(h); continue; } - + close(h); - + psbuf[255] = psbuf[l] = '\0'; - + printf("%5d %3s %c --:-- %s\n", pid, "", state, psbuf); next: } - + closedir(d); } #endif |