-
Notifications
You must be signed in to change notification settings - Fork 0
/
showprocs.c
1636 lines (1389 loc) · 43.6 KB
/
showprocs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** ATOP - System & Process Monitor
**
** The program 'atop' offers the possibility to view the activity of
** the system on system-level as well as process-level.
**
** This source-file contains the Linux-specific functions to calculate
** figures to be visualized.
** ==========================================================================
** Author: JC van Winkel - AT Computing, Nijmegen, Holland
** E-mail: [email protected]
** Date: November 2009
** --------------------------------------------------------------------------
** Copyright (C) 2009 JC van Winkel
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 2, or (at your option) any
** later version.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** --------------------------------------------------------------------------
**
** $Log: showprocs.c,v $
** Revision 1.13 2010/11/12 06:11:58 gerlof
** Sometimes segmentation-fault on particular CPU-types
** due to memcpy i.s.o. memmove when moving memory in overlap.
**
** Revision 1.12 2010/04/23 14:06:42 gerlof
** Added special routined for uid/gid not available for exited processes.
**
** Revision 1.11 2010/01/16 12:54:08 gerlof
** Minor change for CPUNR.
**
** Revision 1.10 2010/01/16 11:37:25 gerlof
** Corrected counters for patched kernels (JC van Winkel).
**
** Revision 1.9 2010/01/08 13:44:47 gerlof
** Added policies batch, iso and idle for scheduling class.
**
** Revision 1.8 2010/01/08 11:25:13 gerlof
** Corrected column-width and priorities of network-stats.
**
** Revision 1.7 2010/01/03 18:26:53 gerlof
** Consistent naming of columns for process-related info.
**
** Revision 1.6 2009/12/19 21:03:21 gerlof
** Alignment of CMD column (JC van Winkel).
**
** Revision 1.5 2009/12/12 10:11:49 gerlof
** Register and display end date and end time for process.
**
** Revision 1.4 2009/12/12 09:05:56 gerlof
** Corrected cumulated disk I/O per user/program (JC van Winkel).
**
** Revision 1.3 2009/12/10 14:01:52 gerlof
** Add EUID, SUID and FSUID (and similar for GID's).
**
** Revision 1.2 2009/12/10 11:56:22 gerlof
** Various bug-solutions.
**
** Revision 1.1 2009/12/10 09:31:23 gerlof
** Initial revision
**
** Initial revision
**
**
** Initial
**
*/
static const char rcsid[] = "$Id: showprocs.c,v 1.13 2010/11/12 06:11:58 gerlof Exp $";
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <signal.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <termio.h>
#include <unistd.h>
#include <stdarg.h>
#include <curses.h>
#include <pwd.h>
#include <grp.h>
#include <regex.h>
#include "atop.h"
#include "photoproc.h"
#include "photosyst.h"
#include "showgeneric.h"
#include "showlinux.h"
static char *columnhead[] = {
[MSORTCPU]= "CPU", [MSORTMEM]= "MEM",
[MSORTDSK]= "DSK", [MSORTNET]= "NET",
};
/***************************************************************/
static int *colspacings; // ugly static var,
// but saves a lot of recomputations
// points to table with intercolumn
// spacings
static proc_printpair newelems[MAXITEMS];
// ugly static var,
// but saves a lot of recomputations
// contains the actual list of items to
// be printed
//
//
/***************************************************************/
/*
* gettotwidth: calculate the sum of widths and number of columns
* Also copys the printpair elements to the static array newelems
* for later removal of lower priority elements.
* Params:
* elemptr: the array of what to print
* nitems: (ref) returns the number of printitems in the array
* sumwidth: (ref) returns the total width of the printitems in the array
* varwidth: (ref) returns the number of variable width items in the array
*/
void
gettotwidth(proc_printpair* elemptr, int *nitems, int *sumwidth, int* varwidth)
{
int i;
int col;
int varw=0;
for (i=0, col=0; elemptr[i].f!=0; ++i)
{
col += (elemptr[i].f->varwidth ? 0 : elemptr[i].f->width);
varw += elemptr[i].f->varwidth;
newelems[i]=elemptr[i]; // copy element
}
newelems[i].f=0;
*nitems=i;
*sumwidth=col;
*varwidth=varw;
}
/***************************************************************/
/*
* getspacings: determine how much extra space there is for
* inter-column space.
* returns an int array this number of spaces to add after each column
* also removes items from the newelems array if the available width
* is lower than what is needed. The lowest priority columns are
* removed first.
*
* Note: this function is only to be called when screen is true.
*/
int *
getspacings(proc_printpair* elemptr)
{
static int spacings[MAXITEMS];
int col=0;
int nitems;
int varwidth=0;
int j;
int maxw=screen ? COLS : linelen; // for non screen: 80 columns max
// get width etc; copy elemptr array to static newelms
gettotwidth(elemptr, &nitems, &col, &varwidth);
/* cases:
* 1) nitems==1: just one column, no spacing needed. Done
*
* 2) total width is more than COLS: remove low prio columns
* 2a) a varwidth column: no spacing needed
* 2b) total width is less than COLS: compute inter spacing
*/
if (nitems==1) // no inter column spacing if 1 column
{
spacings[0]=0;
return spacings;
}
// Check if available width is less than required.
// If so, delete columns to make things fit
// space required:
// width + (nitems-1) * 1 space + 12 for a varwidth column.
while (col + nitems-1+ 12*varwidth > maxw)
{
int lowestprio=999999;
int lowestprio_index=-1;
int i;
for (i=0; i<nitems; ++i)
{
if (newelems[i].prio < lowestprio)
{
lowestprio=newelems[i].prio;
lowestprio_index=i;
}
}
// lowest priority item found, remove from newelems;
col -= newelems[lowestprio_index].f->width;
varwidth -= newelems[lowestprio_index].f->varwidth;
memmove(newelems+lowestprio_index,
newelems+lowestprio_index+1,
(nitems-lowestprio_index)* sizeof(proc_printpair));
// also copies final 0 entry
nitems--;
}
/* if there is a var width column, handle that separately */
if (varwidth)
{
for (j=0; j<nitems; ++j)
{
spacings[j]=1;
if (elemptr[j].f->varwidth)
{
elemptr[j].f->width=maxw-col-(nitems-1);
// only nitems-1 in-between spaces
// needed
}
}
return spacings;
}
/* fixed columns, spread whitespace over columns */
double over=(0.0+maxw-col)/(nitems-1);
double todo=over;
for (j=0; j<nitems-1; ++j) // last column gets no space appended
{
spacings[j]=(int)todo+0.5;
todo-=spacings[j];
todo+=over;
}
spacings[j]=0;
return spacings;
}
/*
* showhdrline: show header line for processes.
* if in interactive mode, also add a page numer
* if in interactive mode, columns are aligned to fill out rows
*/
void
showhdrline(proc_printpair* elemptr, int curlist, int totlist,
char showorder, char autosort)
{
proc_printpair curelem;
char *chead="";
char *autoindic="";
int order=showorder;
int col=0;
int allign;
char pagindic[10];
int pagindiclen;
int n=0;
int bufsz;
int maxw=screen ? COLS : linelen; // for non screen: 80 columns max
colspacings=getspacings(elemptr);
bufsz=maxw+1;
elemptr=newelems; // point to adjusted array
char buf[bufsz+2]; // long live dynamically sized auto arrays...
if (!screen)
{
printg("\n");
}
while ((curelem=*elemptr).f!=0)
{
if (curelem.f->head==0) // empty header==special: SORTITEM
{
chead=columnhead[order];
autoindic= autosort ? "A" : " ";
}
else
{
chead=curelem.f->head;
autoindic="";
}
if (screen)
{
col += sprintf(buf+col, "%s%s%*s", autoindic, chead,
colspacings[n], "");
}
else
{
col += sprintf(buf+col, "%s%s ", autoindic, chead);
}
elemptr++;
n++;
}
if (screen) // add page number, eat from last header if needed...
{
pagindiclen=sprintf(pagindic,"%d/%d", curlist, totlist);
allign=COLS-col-pagindiclen; // extra spaces needed
if (allign >= 0) // allign by adding spaces
{
sprintf(buf+col, "%*s", allign+pagindiclen, pagindic);
}
else
{ // allign by removing from the right
sprintf(buf+col+allign, "%s", pagindic);
}
}
printg("%s", buf);
if (!screen)
{
printg("\n");
}
}
/***************************************************************/
/*
* showprocline: show line for processes.
* if in interactive mode, columns are aligned to fill out rows
* params:
* elemptr: pointer to array of print definitcion structs ptrs
* curstat: the process to print
* perc: the sort order used
* nsecs: number of seconds elapsed between previous and this sample
* avgval: is averaging out per second needed?
*/
void
showprocline(proc_printpair* elemptr, struct pstat *curstat,
double perc, int nsecs, int avgval)
{
proc_printpair curelem;
elemptr=newelems; // point to static array
int n=0;
while ((curelem=*elemptr).f!=0)
{
// what to print? SORTITEM, or active process or
// exited process?
if (curelem.f->head==0) // empty string=sortitem
{
printg("%3.0lf%%", perc); // cannot pass perc
}
else if (curstat->gen.state != 'E') // active process
{
printg("%s", curelem.f->doactiveconvert(curstat,
avgval, nsecs));
}
else // exited process
{
printg("%s", curelem.f->doexitconvert(curstat,
avgval, nsecs));
}
if (screen)
{
printg("%*s",colspacings[n], "");
}
else
{
printg(" ");
}
elemptr++;
n++;
}
if (!screen)
{
printg("\n");
}
}
/*******************************************************************/
/* PROCESS PRINT FUNCTIONS */
/***************************************************************/
char *
procprt_NOTAVAIL_4(struct pstat *curstat, int avgval, int nsecs)
{
return " ?";
}
char *
procprt_NOTAVAIL_5(struct pstat *curstat, int avgval, int nsecs)
{
return " ?";
}
char *
procprt_NOTAVAIL_6(struct pstat *curstat, int avgval, int nsecs)
{
return " ?";
}
char *
procprt_NOTAVAIL_7(struct pstat *curstat, int avgval, int nsecs)
{
return " ?";
}
char *
procprt_PID_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
sprintf(buf, "%5d", curstat->gen.pid);
return buf;
}
char *
procprt_PID_e(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
if (curstat->gen.pid == 0)
return " ?";
sprintf(buf, "%5d", curstat->gen.pid);
return buf;
}
proc_printdef procprt_PID =
{ " PID", "PID", procprt_PID_a, procprt_PID_e, 5 };
/***************************************************************/
char *
procprt_PPID_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
sprintf(buf, "%5d", curstat->gen.ppid);
return buf;
}
char *
procprt_PPID_e(struct pstat *curstat, int avgval, int nsecs)
{
return " ";
}
proc_printdef procprt_PPID =
{ " PPID", "PPID", procprt_PPID_a, procprt_PPID_e, 5 };
/***************************************************************/
char *
procprt_SYSCPU_ae(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2cpustr(curstat->cpu.stime*1000/hertz, buf);
return buf;
}
proc_printdef procprt_SYSCPU =
{ " SYSCPU", "SYSCPU", procprt_SYSCPU_ae, procprt_SYSCPU_ae, 7 };
/***************************************************************/
char *
procprt_USRCPU_ae(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2cpustr(curstat->cpu.utime*1000/hertz, buf);
return buf;
}
proc_printdef procprt_USRCPU =
{ " USRCPU", "USRCPU", procprt_USRCPU_ae, procprt_USRCPU_ae, 7 };
/***************************************************************/
char *
procprt_VGROW_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vgrow*1024, buf, KBFORMAT, 0, 0);
return buf;
}
char *
procprt_VGROW_e(struct pstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
proc_printdef procprt_VGROW =
{ " VGROW", "VGROW", procprt_VGROW_a, procprt_VGROW_e, 6 };
/***************************************************************/
char *
procprt_RGROW_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.rgrow*1024, buf, KBFORMAT, 0, 0);
return buf;
}
char *
procprt_RGROW_e(struct pstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
proc_printdef procprt_RGROW =
{ " RGROW", "RGROW", procprt_RGROW_a, procprt_RGROW_e, 6 };
/***************************************************************/
char *
procprt_MINFLT_ae(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2valstr(curstat->mem.minflt, buf, 6, avgval, nsecs);
return buf;
}
proc_printdef procprt_MINFLT =
{ "MINFLT", "MINFLT", procprt_MINFLT_ae, procprt_MINFLT_ae, 6 };
/***************************************************************/
char *
procprt_MAJFLT_ae(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2valstr(curstat->mem.majflt, buf, 6, avgval, nsecs);
return buf;
}
proc_printdef procprt_MAJFLT =
{ "MAJFLT", "MAJFLT", procprt_MAJFLT_ae, procprt_MAJFLT_ae, 6 };
/***************************************************************/
char *
procprt_VSTEXT_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.shtext*1024, buf, KBFORMAT, 0, 0);
return buf;
}
char *
procprt_VSTEXT_e(struct pstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
proc_printdef procprt_VSTEXT =
{ "VSTEXT", "VSTEXT", procprt_VSTEXT_a, procprt_VSTEXT_e, 6 };
/***************************************************************/
char *
procprt_VSIZE_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.vmem*1024, buf, KBFORMAT, 0, 0);
return buf;
}
char *
procprt_VSIZE_e(struct pstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
proc_printdef procprt_VSIZE =
{ " VSIZE", "VSIZE", procprt_VSIZE_a, procprt_VSIZE_e, 6 };
/***************************************************************/
char *
procprt_RSIZE_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
val2memstr(curstat->mem.rmem*1024, buf, KBFORMAT, 0, 0);
return buf;
}
char *
procprt_RSIZE_e(struct pstat *curstat, int avgval, int nsecs)
{
return " 0K";
}
proc_printdef procprt_RSIZE =
{ " RSIZE", "RSIZE", procprt_RSIZE_a, procprt_RSIZE_e, 6 };
/***************************************************************/
char *
procprt_CMD_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[15];
sprintf(buf, "%-14.14s", curstat->gen.name);
return buf;
}
char *
procprt_CMD_e(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[15]="<";
char helpbuf[15];
sprintf(helpbuf, "<%.12s>", curstat->gen.name);
sprintf(buf, "%-14.14s", helpbuf);
return buf;
}
proc_printdef procprt_CMD =
{ "CMD ", "CMD", procprt_CMD_a, procprt_CMD_e, 14 };
/***************************************************************/
char *
procprt_RUID_ae(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[9];
struct passwd *pwd;
if ( (pwd = getpwuid(curstat->gen.ruid)) )
{
sprintf(buf, "%-8.8s", pwd->pw_name);
}
else
{
snprintf(buf, sizeof buf, "%-8d", curstat->gen.ruid);
}
return buf;
}
proc_printdef procprt_RUID =
{ "RUID ", "RUID", procprt_RUID_ae, procprt_RUID_ae, 8 };
/***************************************************************/
char *
procprt_EUID_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[9];
struct passwd *pwd;
if ( (pwd = getpwuid(curstat->gen.euid)) )
{
sprintf(buf, "%-8.8s", pwd->pw_name);
}
else
{
snprintf(buf, sizeof buf, "%-8d", curstat->gen.euid);
}
return buf;
}
char *
procprt_EUID_e(struct pstat *curstat, int avgval, int nsecs)
{
return "- ";
}
proc_printdef procprt_EUID =
{ "EUID ", "EUID", procprt_EUID_a, procprt_EUID_e, 8 };
/***************************************************************/
char *
procprt_SUID_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[9];
struct passwd *pwd;
if ( (pwd = getpwuid(curstat->gen.suid)) )
{
sprintf(buf, "%-8.8s", pwd->pw_name);
}
else
{
snprintf(buf, sizeof buf, "%-8d", curstat->gen.suid);
}
return buf;
}
char *
procprt_SUID_e(struct pstat *curstat, int avgval, int nsecs)
{
return "- ";
}
proc_printdef procprt_SUID =
{ "SUID ", "SUID", procprt_SUID_a, procprt_SUID_e, 8 };
/***************************************************************/
char *
procprt_FSUID_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[9];
struct passwd *pwd;
if ( (pwd = getpwuid(curstat->gen.fsuid)) )
{
sprintf(buf, "%-8.8s", pwd->pw_name);
}
else
{
snprintf(buf, sizeof buf, "%-8d", curstat->gen.fsuid);
}
return buf;
}
char *
procprt_FSUID_e(struct pstat *curstat, int avgval, int nsecs)
{
return "- ";
}
proc_printdef procprt_FSUID =
{ "FSUID ", "FSUID", procprt_FSUID_a, procprt_FSUID_e, 8 };
/***************************************************************/
char *
procprt_RGID_ae(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
struct group *grp;
char *groupname;
char grname[16];
if ( (grp = getgrgid(curstat->gen.rgid)) )
{
groupname = grp->gr_name;
}
else
{
snprintf(grname, sizeof grname, "%d",curstat->gen.rgid);
groupname = grname;
}
sprintf(buf, "%-8.8s", groupname);
return buf;
}
proc_printdef procprt_RGID =
{ "RGID ", "RGID", procprt_RGID_ae, procprt_RGID_ae, 8 };
/***************************************************************/
char *
procprt_EGID_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
struct group *grp;
char *groupname;
char grname[16];
if ( (grp = getgrgid(curstat->gen.egid)) )
{
groupname = grp->gr_name;
}
else
{
snprintf(grname, sizeof grname, "%d",curstat->gen.egid);
groupname = grname;
}
sprintf(buf, "%-8.8s", groupname);
return buf;
}
char *
procprt_EGID_e(struct pstat *curstat, int avgval, int nsecs)
{
return "- ";
}
proc_printdef procprt_EGID =
{ "EGID ", "EGID", procprt_EGID_a, procprt_EGID_e, 8 };
/***************************************************************/
char *
procprt_SGID_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
struct group *grp;
char *groupname;
char grname[16];
if ( (grp = getgrgid(curstat->gen.sgid)) )
{
groupname = grp->gr_name;
}
else
{
snprintf(grname, sizeof grname, "%d",curstat->gen.sgid);
groupname = grname;
}
sprintf(buf, "%-8.8s", groupname);
return buf;
}
char *
procprt_SGID_e(struct pstat *curstat, int avgval, int nsecs)
{
return "- ";
}
proc_printdef procprt_SGID =
{ "SGID ", "SGID", procprt_SGID_a, procprt_SGID_e, 8 };
/***************************************************************/
char *
procprt_FSGID_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[10];
struct group *grp;
char *groupname;
char grname[16];
if ( (grp = getgrgid(curstat->gen.fsgid)) )
{
groupname = grp->gr_name;
}
else
{
snprintf(grname, sizeof grname,"%d",curstat->gen.fsgid);
groupname = grname;
}
sprintf(buf, "%-8.8s", groupname);
return buf;
}
char *
procprt_FSGID_e(struct pstat *curstat, int avgval, int nsecs)
{
return "- ";
}
proc_printdef procprt_FSGID =
{ "FSGID ", "FSGID", procprt_FSGID_a, procprt_FSGID_e, 8 };
/***************************************************************/
char *
procprt_STDATE_ae(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[11];
convdate(curstat->gen.btime, buf);
return buf;
}
proc_printdef procprt_STDATE =
{ " STDATE ", "STDATE", procprt_STDATE_ae, procprt_STDATE_ae, 10 };
/***************************************************************/
char *
procprt_STTIME_ae(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[9];
convtime(curstat->gen.btime, buf);
return buf;
}
proc_printdef procprt_STTIME =
{ " STTIME ", "STTIME", procprt_STTIME_ae, procprt_STTIME_ae, 8 };
/***************************************************************/
char *
procprt_ENDATE_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[11];
strcpy(buf, " active ");
return buf;
}
char *
procprt_ENDATE_e(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[11];
convdate(curstat->gen.btime + curstat->gen.elaps/hertz, buf);
return buf;
}
proc_printdef procprt_ENDATE =
{ " ENDATE ", "ENDATE", procprt_ENDATE_a, procprt_ENDATE_e, 10 };
/***************************************************************/
char *
procprt_ENTIME_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[9];
strcpy(buf, " active ");
return buf;
}
char *
procprt_ENTIME_e(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[9];
convtime(curstat->gen.btime + curstat->gen.elaps/hertz, buf);
return buf;
}
proc_printdef procprt_ENTIME =
{ " ENTIME ", "ENTIME", procprt_ENTIME_a, procprt_ENTIME_e, 8 };
/***************************************************************/
char *
procprt_THR_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[15];
sprintf(buf, "%4d", curstat->gen.nthr);
return buf;
}
char *
procprt_THR_e(struct pstat *curstat, int avgval, int nsecs)
{
return " 0";
}
proc_printdef procprt_THR =
{ " THR", "THR", procprt_THR_a, procprt_THR_e, 4 };
/***************************************************************/
char *
procprt_TRUN_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[15];
sprintf(buf, "%4d", curstat->gen.nthrrun);
return buf;
}
char *
procprt_TRUN_e(struct pstat *curstat, int avgval, int nsecs)
{
return " 0";
}
proc_printdef procprt_TRUN =
{ "TRUN", "TRUN", procprt_TRUN_a, procprt_TRUN_e, 4 };
/***************************************************************/
char *
procprt_TSLPI_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[15];
sprintf(buf, "%5d", curstat->gen.nthrslpi);
return buf;
}
char *
procprt_TSLPI_e(struct pstat *curstat, int avgval, int nsecs)
{
return " 0";
}
proc_printdef procprt_TSLPI =
{ "TSLPI", "TSLPI", procprt_TSLPI_a, procprt_TSLPI_e, 5 };
/***************************************************************/
char *
procprt_TSLPU_a(struct pstat *curstat, int avgval, int nsecs)
{
static char buf[15];
sprintf(buf, "%5d", curstat->gen.nthrslpu);
return buf;
}
char *
procprt_TSLPU_e(struct pstat *curstat, int avgval, int nsecs)
{
return " 0";
}
proc_printdef procprt_TSLPU =
{ "TSLPU", "TSLPU", procprt_TSLPU_a, procprt_TSLPU_e, 5 };
/***************************************************************/
#define SCHED_NORMAL 0
#define SCHED_FIFO 1
#define SCHED_RR 2
#define SCHED_BATCH 3
#define SCHED_ISO 4
#define SCHED_IDLE 5
char *
procprt_POLI_a(struct pstat *curstat, int avgval, int nsecs)
{