|
|
1.1 root 1: #include <stdio.h>
2: #include <sys/seg.h>
3: #include "ps.h"
4:
5: /*
6: * Print a process table entry along with any supporting information
7: * to file pointer fp.
8: */
9: void
10: print_process( fp, pdata, pargs )
11: FILE *fp;
12: PROC_DATA *pdata;
13: PROC_ARGS *pargs;
14: {
15: PROC *pp;
16: unsigned field_flags;
17: unsigned char proc_state;
18: int len;
19:
20: /*
21: * If we have NULL arguments, just give up.
22: */
23: if ( ( NULL == pdata ) || ( NULL == pargs ) ) {
24: return;
25: }
26:
27: /*
28: * Fetch off the PROC struct--we are going to use it a lot.
29: * If there is no proc struct, we can't print much of anything,
30: * so just give up.
31: */
32: if ( NULL == (pp = pdata->pr_proc) ) {
33: return;
34: }
35:
36: /*
37: * We are going to use the ar_field_flags a lot.
38: */
39: field_flags = pargs->ar_field_flags;
40:
41: if ( PID_ONLY & field_flags ) {
42: fprintf( fp, "%d", pdata->pr_proc->p_pid );
43: return;
44: }
45:
46: /*
47: * We keep a running total of the length of the output line.
48: */
49: len = 0;
50:
51: /*
52: * Except when an exclusive flag is used (like PID_ONLY),
53: * always print the controlling tty and the process id.
54: */
55: print_tty( fp, pp->p_ttdev ); len += 7;
56:
57: fprintf( fp, " %5d", pp->p_pid ); len += 6;
58:
59: /*
60: * Do we want the process group?
61: */
62: if ( GROUPS & field_flags ) {
63: fprintf( fp, " %5d", pp->p_group ); len += 6;
64: }
65:
66: /*
67: * Has a LONG_FMT listing been requested?
68: */
69: if ( LONG_FMT & field_flags ) {
70: /*
71: * Who is our parent?
72: */
73: fprintf( fp, " %5d", pp->p_ppid ); len += 6;
74: /*
75: * What user really owns this process?
76: */
77: fprintf( fp, " %8.8", user_name( pp->p_ruid ) ); len += 9;
78: /*
79: * How large is this process?
80: * NB: We bleed memory by calling kumap this way.
81: */
82: fprintf( fp, " %4ldK",
83: proc_size( kumap( pp->p_segp, sizeof(SEG) ),
84: (REAL_SIZES & pargs->ar_msc_flags)
85: )
86: ); len += 6;
87: /*
88: * How are the process flags set?
89: */
90: fprintf( fp, " %4x", pp->p_flags ); len += 5;
91: /*
92: * Is the process asleep, running, or zombie?
93: */
94: proc_state = state( pp );
95: fprintf( fp, " %c", proc_state ); len += 2;
96:
97: /*
98: * If the process is sleeping, find out what it is
99: * sleeping on. If the process is not sleep, or there
100: * is no u area, just print a filler.
101: */
102: if ( ('S' == proc_state) &&
103: ( NULL != pdata->pr_u ) ) {
104: print_event( fp, pdata->pr_u->u_sleep, pp->p_event );
105: } else {
106: fprintf( fp, " -" );
107: }
108: len += 11;
109: }
110:
111: /*
112: * Have scheduling values been requested?
113: */
114: if ( SCHED & field_flags ) {
115: /*
116: * Print the CPU schedule value.
117: */
118: fprintf( fp, " %9u", pp->p_cval ); len += 10;
119: /*
120: * Print the swap schedule value.
121: */
122: fprintf( fp, " %9u", pp->p_sval ); len += 10;
123: /*
124: * Print the importance value.
125: */
126: fprintf( fp, " %10d", pp->p_ival ); len += 11;
127: /*
128: * Print the response value.
129: */
130: fprintf( fp, " %10d", pp->p_rval ); len += 11;
131: }
132:
133: /*
134: * Have times been requested?
135: */
136: if ( TIMES & field_flags ) {
137: print_time( fp, pp->p_utime ); len += 6;
138: print_time( fp, pp->p_stime ); len += 6;
139: }
140:
141: /*
142: * If we get this far, we always print some form of the command.
143: * It is this line we've been calculating the length for.
144: */
145: fprintf(" "); len += 1;
146: print_command( fp, pdata, pargs, len );
147:
148: fprintf( fp, "\n" );
149: fflush( fp );
150:
151: } /* print_process() */
152:
153: /*
154: * Print out an appropriate header for a given set of process flags.
155: */
156: void
157: print_headers( fp, pargs )
158: FILE *fp;
159: PROC_ARGS *pargs;
160: {
161: unsigned field_flags;
162:
163: /*
164: * We are going to use the ar_field_flags a lot.
165: */
166: field_flags = pargs->ar_field_flags;
167:
168: /*
169: * There are no headers if they are explicitly surpressed, or
170: * if an exclusive flag like PID_ONLY is used.
171: */
172: if ( ( PID_ONLY & field_flags ) ||
173: ( NO_HEAD & pargs->ar_msc_flags ) ) {
174: return;
175: }
176:
177: /*
178: * Except when an exclusive flag is used (like PID_ONLY),
179: * always print the controlling tty and the process id.
180: */
181: fprintf( fp, "TTY PID" );
182:
183: /*
184: * Do we want the process group?
185: */
186: if ( GROUPS & field_flags ) {
187: fprintf( fp, " GROUP" );
188: }
189:
190: /*
191: * Has a LONG_FMT listing been requested?
192: */
193: if ( LONG_FMT & field_flags ) {
194: fprintf( fp, " PPID UID K F S EVENT" );
195: }
196:
197: /*
198: * Have scheduling values been requested?
199: */
200: if ( SCHED & field_flags ) {
201: fprintf( fp, " CVAL SVAL IVAL RVAL" );
202: }
203:
204: /*
205: * Have times been requested?
206: */
207: if ( TIMES & field_flags ) {
208: fprintf( fp, " UTIME STIME" );
209: }
210:
211: } /* print_headers() */
212:
213:
214: /*
215: * Print the name of a tty.
216: */
217: void
218: print_tty( fp, ttdev )
219: FILE *fp;
220: dev_t ttdev;
221: {
222: } /* print_tty() */
223:
224: /*
225: * Print out the reason for a sleep.
226: */
227: void
228: print_event( fp, sleep_str, event )
229: FILE *fp;
230: char *sleep_str;
231: char *event;
232: {
233: /*
234: * Only print the sleep field if it is non-empty.
235: */
236:
237: if ( '\0' != sleep_str[0] ) {
238: fprintf( fp, " %10.10s", sleep_str );
239: } else {
240: /* Otherwise, print the address we are sleeping on. */
241: fprintf( fp, " 0x%08X", event);
242: }
243:
244: fflush( fp );
245: } /* print_event() */
246:
247: /*
248: * Print out a time in HZ.
249: */
250: void
251: print_time( atime )
252: long atime;
253: {
254: register unsigned min;
255:
256: if ((atime=(atime+HZ/2)/HZ) == 0) {
257: printf(" -");
258: return;
259: }
260: if ((min=atime/60) >= 100) {
261: printf("%6d", min);
262: return;
263: }
264: printf(" %2d:%02d", min, (unsigned)atime%60);
265: } /* print_time() */
266:
267: /*
268: * Print the command for this process.
269: */
270: void
271: print_command( fp, pdata, pargs, line_len )
272: FILE *fp;
273: PROC_DATA *pdata;
274: PROC_ARGS *pargs;
275: int line_len;
276: {
277: printf("STUB"); /* STUB */
278: } /* print_command() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.