Mercurial > hg > toybox
annotate toys/pending/ps.c @ 1775:57f2a26fa92c draft toast
To ensure that toybox can be installed alongside busybox without
confusing update-alternatives, the paths of the links installed by toybox should
match those installed by busybox. This is accomplished by changing the flags
of a few tools within toybox.
author | Paul Barker <paul@paulbarker.me.uk> |
---|---|
date | Sat, 04 Apr 2015 11:58:06 -0500 |
parents | 014a5e821603 |
children |
rev | line source |
---|---|
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
1 /* ps.c - show process list |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
3 * Copyright 2015 Rob Landley <rob@landley.net> |
1290 | 4 * |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
6 * And http://kernel.org/doc/Documentation/filesystems/proc.txt Table 1-4 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
7 * And linux kernel source fs/proc/array.c function do_task_stat() |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
8 * |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
9 * Deviation from posix: no -n, "-o tty" called "TTY" not "TT", |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
11 USE_PS(NEWTOY(ps, "aAdeflo*", TOYFLAG_USR|TOYFLAG_BIN)) |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 config PS |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 bool "ps" |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 default n |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 help |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
17 usage: ps [-Aade] [-fl] [-gG GROUP] [-o FIELD] [-p PID] [-t TTY] [-u USER] |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
18 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
19 List processes. |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
20 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
21 -A All processes |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
22 -a Processes with terminals, except session leaders |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
23 -d Processes that aren't session leaders |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
24 -e Same as -A |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
25 -f Full listing |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
26 -l Long listing |
1290 | 27 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
28 -g Processes belonging to these session leaders |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
29 -G Processes with these real group IDs |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
30 -o Show FIELDS for each process |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
31 -p select by PID |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
32 -t select by TTY |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
33 -u select by USER |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
34 -U select by USER |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
35 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
36 GROUP, FIELD, PID, TTY, and USER are comma separated lists. |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
37 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
38 OUTPUT (-o) FIELDS: |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
39 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
40 S Linux defines the process state letters as: |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
41 R (running) S (sleeping) D (disk sleep) T (stopped) t (tracing stop) |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
42 Z (zombie) X (dead) x (dead) K (wakekill) W (waking) |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
43 F Process flags (PF_*) from linux source file include/sched.h |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
44 (in octal rather than hex because posix inexplicably says so) |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
45 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
46 Default is PID,TTY,TIME,CMD With -f UID,PID,PPID,C,STIME,TTY,TIME,CMD |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
47 With -l F,S,UID,PID,PPID,C,PRI,NI,ADDR,SZ,WCHAN,TTY,TIME,CMD |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 */ |
1290 | 49 |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 #define FOR_ps |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 #include "toys.h" |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 GLOBALS( |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
54 struct arg_list *o; |
1710 | 55 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
56 unsigned width; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
57 dev_t tty; |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
58 void *fields; |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
59 long uptime; |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 ) |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
62 /* |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
63 l l fl a fl fl l l l l l f a a a |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
64 F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
65 ruser user rgroup group pid ppid pgid pcpu vsz nice etime time tty comm args |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
67 todo: thread support /proc/$d/task/%d/stat |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
68 man page: F flags mean... |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
69 */ |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
71 struct strawberry { |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
72 struct strawberry *next, *prev; |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
73 short which, len; |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
74 char title[]; |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
75 }; |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
76 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
77 // dirtree callback. |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
78 // toybuf used as: 1024 /proc/$PID/stat, 1024 slot[], 2048 /proc/$PID/cmdline |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
79 static int do_ps(struct dirtree *new) |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
80 { |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
81 struct strawberry *field; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
82 long long *slot = (void *)(toybuf+1024); |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
83 char *name, *s, state; |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
84 int nlen, i, fd, len, width = TT.width; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
85 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
86 if (!new->parent) return DIRTREE_RECURSE; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
87 if (!(*slot = atol(new->name))) return 0; |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
89 // name field limited to 256 bytes by VFS, plus 40 fields * max 20 chars: |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
90 // 1000-ish total, but some forced zero so actually there's headroom. |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
91 sprintf(toybuf, "%lld/stat", *slot); |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
92 if (!readfileat(dirtree_parentfd(new), toybuf, toybuf, 1024)) return 0; |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
93 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
94 // parse oddball fields (name and state) |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
95 if (!(s = strchr(toybuf, '('))) return 0; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
96 for (name = ++s; *s != ')'; s++) if (!*s) return 0; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
97 nlen = s++-name; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
98 if (1>sscanf(++s, " %c%n", &state, &i)) return 0; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
99 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
100 // parse numeric fields |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
101 for (len = 1; len<100; len++) |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
102 if (1>sscanf(s += i, " %lld%n", slot+len, &i)) break; |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
103 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
104 // skip entries we don't care about. |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
105 if ((toys.optflags&(FLAG_a|FLAG_d)) && getsid(*slot)==*slot) return 0; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
106 if ((toys.optflags&FLAG_a) && !slot[4]) return 0; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
107 if (!(toys.optflags*(FLAG_a|FLAG_d|FLAG_A|FLAG_e)) && TT.tty!=slot[4]) |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
108 return 0; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
109 |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
110 // 0 "F", "S", "UID", "PID", "PPID", "C", "PRI", |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
111 // 7 "NI", "ADDR", "SZ", "WCHAN", "STIME", "TTY", "TIME", "CMD", |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
112 //15 "COMMAND", "ELAPSED", "GROUP", "%CPU", "PGID", "RGROUP", |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
113 //21 "RUSER", "USER", "VSZ" |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
114 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
115 for (field = TT.fields; field; field = field->next) { |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
116 char *out = toybuf+2048; |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
117 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
118 // Default: unsupported (5 "C") |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
119 sprintf(out, "-"); |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
120 |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
121 // PID, PPID, PRI, NI, ADDR, SZ |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
122 if (-1 != (i = stridx((char[]){3,4,6,7,8,9,0}, field->which))) |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
123 sprintf(out, ((1<<i)&0x10) ? "%llx" : "%lld", |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
124 slot[((char[]){0,2,16,17,22})[i]]>>(((1<<i)&0x20) ? 12 : 0)); |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
125 // F |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
126 else if (!(i = field->which)) sprintf(out, "%llo", slot[7]); |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
127 // S |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
128 else if (i == 1) |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
129 sprintf(out, "%c", state); |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
130 // UID and USER |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
131 else if (i == 2 || i == 22) { |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
132 sprintf(out, "%d", new->st.st_uid); |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
133 if (i == 2 || (toys.optflags&FLAG_f)) { |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
134 struct passwd *pw = getpwuid(new->st.st_uid); |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
135 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
136 if (pw) out = pw->pw_name; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
137 } |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
138 // WCHAN |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
139 } else if (i==10) { |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
140 sprintf(toybuf+512, "%lld/wchan", *slot); |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
141 readfileat(dirtree_parentfd(new), toybuf+512, out, 2047); |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
142 |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
143 // STIME |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
144 // TTY |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
145 } else if (i==12) { |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
146 |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
147 // Can we readlink() our way to a name? |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
148 for (i=0; i<3; i++) { |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
149 struct stat st; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
150 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
151 sprintf(toybuf+512, "%lld/fd/%i", *slot, i); |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
152 fd = dirtree_parentfd(new); |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
153 if (!fstatat(fd, toybuf+512, &st, 0) && S_ISCHR(st.st_mode) |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
154 && st.st_rdev == slot[4] |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
155 && 0<(len = readlinkat(fd, toybuf+512, out, 2047))) |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
156 { |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
157 out[len] = 0; |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
158 if (!strncmp(out, "/dev/", 5)) out += 5; |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
159 |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
160 break; |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
161 } |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
162 } |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
163 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
164 // Couldn't find it, show major:minor |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
165 if (i==3) { |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
166 i = slot[4]; |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
167 sprintf(out, "%d:%d", (i>>8)&0xfff, ((i>>12)&0xfff00)|(i&0xff)); |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
168 } |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
169 |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
170 // TIME |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
171 } else if (i==13 || i==16) { |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
172 long seconds = (i==16) ? slot[20] : slot[11]+slot[12], ll = 60*60*24; |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
173 |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
174 seconds /= sysconf(_SC_CLK_TCK); |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
175 if (i==16) seconds = TT.uptime-seconds; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
176 for (s = out, i = 0; i<4; i++) { |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
177 if (i>1 || seconds > ll) |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
178 s += sprintf(s, (i==3) ? "%02ld" : "%ld%c", seconds/ll, "-::"[i]); |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
179 seconds %= ll; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
180 ll /= i ? 60 : 24; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
181 } |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
182 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
183 //16 "ELAPSED", "GROUP", "%CPU", "PGID", "RGROUP", |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
184 //21 "RUSER", -, "VSZ" |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
185 |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
186 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
187 // Command line limited to 2k displayable. We could dynamically malloc, but |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
188 // it'd almost never get used, querying length of a proc file is awkward, |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
189 // fixed buffer is nommu friendly... Wait for somebody to complain. :) |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
190 } else if (i == 14 || i == 15) { |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
191 int fd; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
192 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
193 len = 0; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
194 sprintf(out, "%lld/cmdline", *slot); |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
195 fd = openat(dirtree_parentfd(new), out, O_RDONLY); |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
196 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
197 if (fd != -1) { |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
198 if (0<(len = read(fd, out, 2047))) { |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
199 out[len] = 0; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
200 for (i = 0; i<len; i++) if (out[i] < ' ') out[i] = ' '; |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
201 } |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
202 close(fd); |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
203 } |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
204 if (len<1) sprintf(out, "[%.*s]", nlen, name); |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
205 } |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
206 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
207 i = width<field->len ? width : field->len; |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
208 width -= printf(" %*.*s", i, field->next ? i : width, out); |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
209 } |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
210 xputc('\n'); |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
211 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
212 return 0; |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
213 } |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
214 |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
215 void ps_main(void) |
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
216 { |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
217 struct strawberry *field; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
218 // Octal output code followed by header name |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
219 char *typos[] = { |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
220 "F", "S", "UID", "PID", "PPID", "C", "PRI", |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
221 "NI", "ADDR", "SZ", "WCHAN", "STIME", "TTY", "TIME", "CMD", |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
222 "COMMAND", "ELAPSED", "GROUP", "%CPU", "PGID", "RGROUP", |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
223 "RUSER", "USER", "VSZ" |
1290 | 224 }; |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
225 int i, fd = -1; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
226 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
227 // l l fl a fl fl l l l l l f a a a |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
228 // F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
229 // 7 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
230 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
231 TT.width = 80; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
232 terminal_size(&TT.width, 0); |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
233 TT.width--; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
234 |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
235 // find controlling tty, falling back to /dev/tty if none |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
236 for (i = fd = 0; i < 4; i++) { |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
237 struct stat st; |
1739
1134cfb98257
More ps cleanup, mostly refactoring.
Rob Landley <rob@landley.net>
parents:
1738
diff
changeset
|
238 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
239 if (i != 3 || -1 != (i = fd = open("/dev/tty", O_RDONLY))) { |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
240 if (isatty(i) && !fstat(i, &st)) { |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
241 TT.tty = st.st_rdev; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
242 break; |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
243 } |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
244 } |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
245 } |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
246 if (fd != -1) close(fd); |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
247 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
248 sysinfo((void *)toybuf); |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
249 // Because "TT.uptime = *(long *)toybuf;" triggers a bug in gcc. |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
250 { |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
251 long *sigh = (long *)toybuf; |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
252 TT.uptime = *sigh; |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
253 } |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
254 |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
255 // Select fields |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
256 if (toys.optflags&FLAG_o) { |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
257 printf("todo\n"); |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
258 } else { |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
259 unsigned short def = 0x7008; |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
260 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
261 if (toys.optflags&FLAG_f) def = 0x783c; |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
262 if (toys.optflags&FLAG_l) def = 0x77ff; |
1710 | 263 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
264 // order of fields[] matches posix STDOUT section, so add enabled XSI |
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
265 // defaults according to bitmask |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
266 |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
267 for (i=0; def>>i; i++) { |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
268 int len = strlen(typos[i]); |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
269 |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
270 if (!((def>>i)&1)) continue; |
1710 | 271 |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
272 field = xmalloc(sizeof(struct strawberry)+len+1); |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
273 field->which = i; |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
274 field->len = len; |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
275 strcpy(field->title, typos[i]); |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
276 dlist_add_nomalloc((void *)&TT.fields, (void *)field); |
1772
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
277 } |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
278 } |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
279 dlist_terminate(TT.fields); |
4172d341590a
ps checkpoint du jour. Does not work yet.
Rob Landley <rob@landley.net>
parents:
1771
diff
changeset
|
280 |
1774
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
281 for (field = TT.fields; field; field = field->next) |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
282 printf(" %*s", field->len, field->title); |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
283 xputc('\n'); |
014a5e821603
Another in-progress ps snapshot.
Rob Landley <rob@landley.net>
parents:
1772
diff
changeset
|
284 |
1771
22c10aa56cfb
Redoing ps from scratch. Random checkpoint that probably doesn't even compile.
Rob Landley <rob@landley.net>
parents:
1739
diff
changeset
|
285 dirtree_read("/proc", do_ps); |
1020
fe7725c1819a
Add watch and ps, sent by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
286 } |