5 typedef struct Proc Proc;
8 Proc *first, *parent, *next;
21 for(p = hash[pid % nelem(hash)]; p; p = p->hash)
32 p = mallocz(sizeof(*p), 1);
34 sysfatal("malloc: %r");
36 p->hash = hash[pid % nelem(hash)];
37 hash[pid % nelem(hash)] = p;
47 snprint(b, sizeof(b), "%d/ppid", pid);
50 memset(b, 0, sizeof b);
51 if(read(fd, b, sizeof b-1) >= 0){
67 par = getproc(theppid(pid));
71 for(l = &par->first; *l; l = &((*l)->next))
84 fd = open(".", OREAD);
87 rc = dirreadall(fd, &d);
89 sysfatal("dirreadall: %r");
91 for(i = 0; i < rc; i++)
93 addproc(atoi(d[i].name));
94 for(i = 0; i < rc; i++)
96 addppid(atoi(d[i].name));
106 fd = open(file, OREAD);
110 while((rc = read(fd, b, sizeof b)) > 0){
114 n += Bwrite(&bout, b, rc);
126 snprint(b, sizeof(b), "%d/args", pid);
129 snprint(b, sizeof(b), "%d/status", pid);
132 memset(b, 0, sizeof b);
133 if(read(fd, b, 27) > 0){
135 while(p > b && p[-1] == ' ')
137 Bprint(&bout, "%s", b);
144 descend(Proc *p, Rune *r)
150 *r = last == L' ' ? L'└' : L'├';
152 Bprint(&bout, "%-11d %S", p->pid, buf);
158 for(q = p->first; q; q = q->next) {
169 descend(getproc(0), buf);
175 Binit(&bout, 1, OWRITE);
176 if(chdir("/proc")==-1)
177 sysfatal("chdir: %r");