16 main(int argc, char *argv[])
18 int fd, i, tot, none = 1;
36 Binit(&bout, 1, OWRITE);
37 if(chdir("/proc")==-1)
42 tot = dirreadall(fd, &dir);
44 fprint(2, "ps: empty directory /proc\n");
47 mem = malloc(tot*sizeof(Dir*));
51 qsort(mem, tot, sizeof(Dir*), cmp);
58 error("no processes; bad #p");
65 ulong utime, stime, rtime, size;
66 int argc, basepri, fd, i, n, pri;
67 char args[256], *argv[16], buf[64], nbuf[13], pbuf[8], rbuf[20], rbuf1[20], status[4096];
69 sprint(buf, "%s/status", s);
70 fd = open(buf, OREAD);
73 n = read(fd, status, sizeof status-1);
79 if((argc = tokenize(status, argv, nelem(argv)-1)) < 12)
92 utime = strtoul(argv[3], 0, 0)/1000;
93 stime = strtoul(argv[4], 0, 0)/1000;
94 rtime = strtoul(argv[5], 0, 0)/1000;
95 size = strtoul(argv[9], 0, 0);
98 snprint(nbuf, sizeof nbuf, " %8s", "?");
99 sprint(buf, "%s/noteid", s);
100 fd = open(buf, OREAD);
102 n = read(fd, buf, sizeof buf-1);
105 snprint(nbuf, sizeof nbuf, " %7ud", atoi(buf));
111 basepri = strtoul(argv[10], 0, 0);
112 pri = strtoul(argv[11], 0, 0);
113 sprint(pbuf, " %2d %2d", basepri, pri);
119 sprint(rbuf, " %lud:%02lud:%02lud:%02lud", rtime/86400, (rtime/3600)%24, (rtime/60)%60, rtime%60);
120 else if(rtime >= 3600)
121 sprint(rbuf, " %lud:%02lud:%02lud", rtime/3600, (rtime/60)%60, rtime%60);
123 sprint(rbuf, " %lud:%02lud", rtime/60, rtime%60);
124 sprint(rbuf1, "%12s", rbuf);
128 Bprint(&bout, "%-10s %8s%s%s %4lud:%.2lud %3lud:%.2lud %s %7ludK %-8.8s ",
141 Bprint(&bout, "%s\n", argv[0]);
145 sprint(buf, "%s/args", s);
146 fd = open(buf, OREAD);
149 n = read(fd, args, sizeof args-1);
159 Bprint(&bout, "%s\n", args);
163 Bprint(&bout, "%s ?\n", argv[0]);
169 fprint(2, "ps: %s: ", s);
175 cmp(void *va, void *vb)
181 return atoi((*a)->name) - atoi((*b)->name);