Research V7 development
[unix-history] / usr / src / cmd / pstat.c
CommitLineData
1f0f2153
KT
1/*
2 * Print system stuff
3 */
4
5#define mask(x) (x&0377)
6#include <sys/param.h>
7#include <sys/conf.h>
8#include <sys/tty.h>
9
10char *fcore = "/dev/mem";
11char *fnlist = "/unix";
12int fc;
13
14struct setup {
15 char name[8];
16 int type;
17 unsigned value;
18} setup[] = {
19#define SINODE 0
20 "_inode", 0, 0,
21#define STEXT 1
22 "_text", 0, 0,
23#define SPROC 2
24 "_proc", 0, 0,
25#define SDH 3
26 "_dh11", 0, 0,
27#define SNDH 4
28 "_ndh11", 0, 0,
29#define SKL 5
30 "_kl11", 0, 0,
31#define SFIL 6
32 "_file", 0, 0,
33 0,
34};
35
36int inof;
37int txtf;
38int prcf;
39int ttyf;
40int usrf;
41long ubase;
42int filf;
43int allflg;
44
45main(argc, argv)
46char **argv;
47{
48
49 while (--argc && **++argv == '-') {
50 while (*++*argv)
51 switch (**argv) {
52
53 case 'a':
54 allflg++;
55 break;
56
57 case 'i':
58 inof++;
59 break;
60
61 case 'x':
62 txtf++;
63 break;
64 case 'p':
65 prcf++;
66 break;
67
68 case 't':
69 ttyf++;
70 break;
71
72 case 'u':
73 if (--argc == 0)
74 break;
75 usrf++;
76 ubase = oatoi(*++argv);
77 break;
78
79 case 'f':
80 filf++;
81 break;
82 }
83 }
84 if (argc>0)
85 fcore = argv[0];
86 if ((fc = open(fcore, 0)) < 0) {
87 printf("Can't find %s\n", fcore);
88 exit(1);
89 }
90 if (argc>1)
91 fnlist = argv[1];
92 nlist(fnlist, setup);
93 if (setup[SINODE].type == -1) {
94 printf("no namelist\n");
95 exit(1);
96 }
97 if (inof)
98 doinode();
99 if (txtf)
100 dotext();
101 if (ttyf)
102 dotty();
103 if (prcf)
104 doproc();
105 if (usrf)
106 dousr();
107 if (filf)
108 dofil();
109}
110
111doinode()
112{
113#include <sys/inode.h>
114 register struct inode *ip;
115 struct inode xinode[NINODE];
116 register int nin, loc;
117
118 nin = 0;
119 lseek(fc, (long)setup[SINODE].value, 0);
120 read(fc, (char *)xinode, sizeof(xinode));
121 for (ip = xinode; ip < &xinode[NINODE]; ip++)
122 if (ip->i_count)
123 nin++;
124 printf("%d active inodes\n", nin);
125 printf(" LOC FLAGS CNT DEVICE INO MODE NLK UID SIZE/DEV\n");
126 loc = setup[SINODE].value;
127 for (ip = xinode; ip < &xinode[NINODE]; ip++, loc += sizeof(xinode[0])) {
128 if (ip->i_count == 0)
129 continue;
130 printf("%7.1o ", loc);
131 putf(ip->i_flag&ILOCK, 'L');
132 putf(ip->i_flag&IUPD, 'U');
133 putf(ip->i_flag&IACC, 'A');
134 putf(ip->i_flag&IMOUNT, 'M');
135 putf(ip->i_flag&IWANT, 'W');
136 putf(ip->i_flag&ITEXT, 'T');
137 printf("%4d", ip->i_count&0377);
138 printf("%3d,%3d", major(ip->i_dev), minor(ip->i_dev));
139 printf("%6l", ip->i_number);
140 printf("%7o", ip->i_mode);
141 printf("%4d", ip->i_nlink);
142 printf("%4d", ip->i_uid);
143 if ((ip->i_mode&IFMT)==IFBLK || (ip->i_mode&IFMT)==IFCHR)
144 printf("%6d,%3d", major(ip->i_un.i_rdev), minor(ip->i_un.i_rdev));
145 else
146 printf("%10ld", ip->i_size);
147 printf("\n");
148 }
149}
150
151putf(v, n)
152{
153 if (v)
154 printf("%c", n);
155 else
156 printf(" ");
157}
158
159dotext()
160{
161#include <sys/text.h>
162 register struct text *xp;
163 struct text xtext[NTEXT];
164 register loc;
165 int ntx;
166
167 ntx = 0;
168 lseek(fc, (long)setup[STEXT].value, 0);
169 read(fc, (char *)xtext, sizeof(xtext));
170 for (xp = xtext; xp < &xtext[NTEXT]; xp++)
171 if (xp->x_iptr!=NULL)
172 ntx++;
173 printf("%d text segments\n", ntx);
174 printf(" LOC FLAGS DADDR CADDR SIZE IPTR CNT CCNT\n");
175 loc = setup[STEXT].value;
176 for (xp = xtext; xp < &xtext[NTEXT]; xp++, loc+=sizeof(xtext[0])) {
177 if (xp->x_iptr == NULL)
178 continue;
179 printf("%7.1o", loc);
180 printf(" ");
181 putf(xp->x_flag&XTRC, 'T');
182 putf(xp->x_flag&XWRIT, 'W');
183 putf(xp->x_flag&XLOAD, 'L');
184 putf(xp->x_flag&XLOCK, 'K');
185 putf(xp->x_flag&XWANT, 'w');
186 printf("%5u", xp->x_daddr);
187 printf("%7.1o", xp->x_caddr);
188 printf("%5d", xp->x_size);
189 printf("%8.1o", xp->x_iptr);
190 printf("%4d", xp->x_count&0377);
191 printf("%4d", xp->x_ccount);
192 printf("\n");
193 }
194}
195
196doproc()
197{
198#include <sys/proc.h>
199 struct proc xproc[NPROC];
200 register struct proc *pp;
201 register loc, np;
202
203 lseek(fc, (long)setup[SPROC].value, 0);
204 read(fc, (char *)xproc, sizeof(xproc));
205 np = 0;
206 for (pp=xproc; pp < &xproc[NPROC]; pp++)
207 if (pp->p_stat)
208 np++;
209 printf("%d processes\n", np);
210 printf(" LOC S F PRI SIGNAL UID TIM CPU NI PGRP PID PPID ADDR SIZE WCHAN LINK TEXTP CLKT\n");
211 for (loc=setup[SPROC].value,pp=xproc; pp<&xproc[NPROC]; pp++,loc+=sizeof(xproc[0])) {
212 if (pp->p_stat==0 && allflg==0)
213 continue;
214 printf("%6o", loc);
215 printf("%2d", pp->p_stat);
216 printf("%3o", pp->p_flag);
217 printf("%5d", pp->p_pri);
218 printf("%7o", pp->p_sig);
219 printf("%4d", pp->p_uid&0377);
220 printf("%4d", pp->p_time&0377);
221 printf("%4d", pp->p_cpu&0377);
222 printf("%3d", pp->p_nice);
223 printf("%6d", pp->p_pgrp);
224 printf("%6d", pp->p_pid);
225 printf("%6d", pp->p_ppid);
226 printf("%5o", pp->p_addr);
227 printf("%5o", pp->p_size);
228 printf("%7o", pp->p_wchan);
229 printf("%7o", pp->p_link);
230 printf("%7o", pp->p_textp);
231 printf(" %u", pp->p_clktim);
232 printf("\n");
233 }
234}
235
236dotty()
237{
238 struct tty dh11[48];
239 int ndh;
240 register struct tty *tp;
241 register char *mesg;
242
243 printf("1 kl11\n");
244 lseek(fc, (long)setup[SKL].value, 0);
245 read(fc, (char *)dh11, sizeof(dh11[0]));
246 mesg = " # RAW CAN OUT MODE ADDR DEL COL STATE PGRP\n";
247 printf(mesg);
248 ttyprt(0, &dh11[0]);
249 if (setup[SNDH].type == -1)
250 return;
251 lseek(fc, (long)setup[SNDH].value, 0);
252 read(fc, (char *)&ndh, sizeof(ndh));
253 printf("%d dh lines\n", ndh);
254 lseek(fc, (long)setup[SDH].value, 0);
255 read(fc, (char *)dh11, sizeof(dh11));
256 for (tp = dh11; tp < &dh11[ndh]; tp++)
257 ttyprt(tp-dh11, tp);
258}
259
260ttyprt(n, atp)
261struct tty *atp;
262{
263 register struct tty *tp;
264
265 tp = atp;
266 printf("%2d", n);
267 printf("%4d", tp->t_rawq.c_cc);
268 printf("%4d", tp->t_canq.c_cc);
269 printf("%4d", tp->t_outq.c_cc);
270 printf("%8.1o", tp->t_flags);
271 printf("%8.1o", tp->t_addr);
272 printf("%3d", tp->t_delct);
273 printf("%4d ", tp->t_col);
274 putf(tp->t_state&TIMEOUT, 'T');
275 putf(tp->t_state&WOPEN, 'W');
276 putf(tp->t_state&ISOPEN, 'O');
277 putf(tp->t_state&CARR_ON, 'C');
278 putf(tp->t_state&BUSY, 'B');
279 putf(tp->t_state&ASLEEP, 'A');
280 putf(tp->t_state&XCLUDE, 'X');
281 putf(tp->t_state&HUPCLS, 'H');
282 printf("%6d", tp->t_pgrp);
283 printf("\n");
284}
285
286dousr()
287{
288#include <sys/dir.h>
289#include <sys/user.h>
290 union {
291 struct user rxu;
292 char fxu[ctob(USIZE)];
293 } xu;
294 register struct user *up;
295 register i;
296
297 lseek(fc, ubase<<6, 0);
298 read(fc, (char *)&xu, sizeof(xu));
299 up = &xu.rxu;
300 printf("rsav %.1o %.1o\n", up->u_rsav[0], up->u_rsav[1]);
301 printf("segflg, error %d, %d\n", up->u_segflg, up->u_error);
302 printf("uids %d,%d,%d,%d\n", up->u_uid,up->u_gid,up->u_ruid,up->u_rgid);
303 printf("procp %.1o\n", up->u_procp);
304 printf("base, count, offset %.1o %.1o %ld\n", up->u_base,
305 up->u_count, up->u_offset);
306 printf("cdir %.1o\n", up->u_cdir);
307 printf("dbuf %.14s\n", up->u_dbuf);
308 printf("dirp %.1o\n", up->u_dirp);
309 printf("dent %d %.14s\n", up->u_dent.d_ino, up->u_dent.d_name);
310 printf("pdir %.1o\n", up->u_pdir);
311 printf("dseg");
312 for (i=0; i<8; i++)
313 printf("%8.1o", up->u_uisa[i]);
314 printf("\n ");
315 for (i=0; i<8; i++)
316 printf("%8.1o", up->u_uisd[i]);
317 if (up->u_sep) {
318 printf("\ntseg");
319 for (i=8; i<16; i++)
320 printf("%8.1o", up->u_uisa[i]);
321 printf("\n ");
322 for (i=8; i<16; i++)
323 printf("%8.1o", up->u_uisd[i]);
324 }
325 printf("\nfile");
326 for (i=0; i<10; i++)
327 printf("%8.1o", up->u_ofile[i]);
328 printf("\n ");
329 for (i=10; i<NOFILE; i++)
330 printf("%8.1o", up->u_ofile[i]);
331 printf("\nargs");
332 for (i=0; i<5; i++)
333 printf(" %.1o", up->u_arg[i]);
334 printf("\nsizes %.1o %.1o %.1o\n", up->u_tsize, up->u_dsize, up->u_ssize);
335 printf("sep %d\n", up->u_sep);
336 printf("qsav %.1o %.1o\n", up->u_qsav[0], up->u_qsav[1]);
337 printf("ssav %.1o %.1o\n", up->u_ssav[0], up->u_ssav[1]);
338 printf("sigs");
339 for (i=0; i<NSIG; i++)
340 printf(" %.1o", up->u_signal[i]);
341 printf("\ntimes %ld %ld\n", up->u_utime/60, up->u_stime/60);
342 printf("ctimes %ld %ld\n", up->u_cutime/60, up->u_cstime/60);
343 printf("ar0 %.1o\n", up->u_ar0);
344/*
345 printf("prof");
346 for (i=0; i<4; i++)
347 printf(" %.1o", up->u_prof[i]);
348*/
349 printf("\nintflg %d\n", up->u_intflg);
350 printf("ttyp %.1o\n", up->u_ttyp);
351 printf("ttydev %d,%d\n", major(up->u_ttyd), minor(up->u_ttyd));
352 printf("comm %.14s\n", up->u_comm);
353}
354
355oatoi(s)
356char *s;
357{
358 register v;
359
360 v = 0;
361 while (*s)
362 v = (v<<3) + *s++ - '0';
363 return(v);
364}
365
366dofil()
367{
368#include <sys/file.h>
369 struct file xfile[NFILE];
370 register struct file *fp;
371 register nf;
372 int loc;
373
374 nf = 0;
375 lseek(fc, (long)setup[SFIL].value, 0);
376 read(fc, (char *)xfile, sizeof(xfile));
377 for (fp=xfile; fp < &xfile[NFILE]; fp++)
378 if (fp->f_count)
379 nf++;
380 printf("%d open files\n", nf);
381 printf(" LOC FLG CNT INO OFFS\n");
382 for (fp=xfile,loc=setup[SFIL].value; fp < &xfile[NFILE]; fp++,loc+=sizeof(xfile[0])) {
383 if (fp->f_count==0)
384 continue;
385 printf("%7.1o ", loc);
386 putf(fp->f_flag&FREAD, 'R');
387 putf(fp->f_flag&FWRITE, 'W');
388 putf(fp->f_flag&FPIPE, 'P');
389 printf("%4d", mask(fp->f_count));
390 printf("%8.1o", fp->f_inode);
391 printf(" %ld\n", fp->f_un.f_offset);
392 }
393}