ADD_BY_MPID 20-APR-1987 21:08:52 VAX C V2.2-015 Page 1 V1.0 20-APR-1987 21:08:46 [INTPROC$TIMEOUT]ADD_BY_MPID.C;59 (1) 1 /* 2 **++ 3 ** 4 ** ADD_BY_MPID.C 5 ** 6 ** Abstract: 7 ** 8 ** Uses process information array and sums CPU time of all elements 9 ** having the same master pid. 10 ** 11 ** Calls: 12 ** 13 ** SORT_PROC_MPID 14 ** ZERO_RECORD 15 ** EXCEPTION 16 ** 17 ** Authors: 18 ** 19 ** Duane Chandler 20 ** 21 ** 22 ** Creation date: 5-FEB-1987 23 ** 24 ** Modification history: 25 ** 26 **-- 27 **/ 28 29 #include "user$disk:[user0.duane.intproc$timeout]intproc$common.h" 30 1 #define FOREVER while(1) 31 1 #define MAXPROC 1000 32 1 33 1 #define LNMLEN 255 34 1 #define MSGLEN 255 35 1 #define USERNAMLEN 13 36 1 #define TERMLEN 9 37 1 38 1 #define WARN 0 39 1 #define PUNT 1 40 1 41 1 42 1 43 1 /* Structure to hold info about each process */ 44 1 struct process 45 1 { 46 1 unsigned int mpid; /* master pid in process tree */ 47 1 unsigned int pid; /* process id */ 48 1 char usernam[USERNAMLEN]; /* username */ 1 char usernam[13]; /* username */ 49 1 unsigned int cputim; /* cputime used */ 50 1 char term[TERMLEN]; /* terminal */ 1 char term[9]; /* terminal */ 51 1 unsigned short tmocnt; /* # of passes w/o using more cpu */ 52 1 unsigned short mode; /* execution mode */ 53 1 }; 54 55 56 unsigned int sort_proc_mpid(), 57 exception(); 58 59 unsigned int add_by_mpid( proc_info, numproc ) 60 struct process *proc_info[]; /* array of process records */ 61 unsigned int numproc; /* number of those processes to */ 62 /* look at this time */ 63 { 64 1 unsigned int count = 0, i = 0, j = 0, /* counters */ 65 1 length = 0; /* length of each record*/ 66 1 struct process proc_zero = {0}; /* zero filler */ 67 1 68 1 69 1 length = sizeof( struct process ); /* set length to what it is */ 70 1 /* supposed to be */ 71 1 72 1 if( numproc == 0 ) return( 0 ); 73 1 74 1 75 1 /* This tends to be sort of confusing. i is set to point to the */ 76 1 /* first element of the process array. j is set to point to the */ 77 1 /* element following the one i is pointing to. If the master pid */ 78 1 /* pointed to by j is the same as the one pointed to by i, the cpu */ 79 1 /* times of each are added together and the sum placed into the ith */ 80 1 /* element, then the jth element is completely zeroed. If the */ 81 1 /* master pids are different, i is then set to point where j does */ 82 1 /* and the process is repeated until j has pointed at the last */ 83 1 /* element. When the cpu times are accumulated, the terminal name */ 84 1 /* in the jth element, if it exists, is copied into the terminal */ 85 1 /* name of the ith element, since the terminal name only shows up */ 86 1 /* from $GETJPI for the master process and not the subprocesses. */ 87 1 /* This routine also checks for exceptions and zeros those records. */ 88 1 /* Before the data is totaled, it is sorted by master pid in */ 89 1 /* descending order. After everything has been totaled, */ 90 1 /* sort_proc_mpid is called to move all the zero elements so they */ 91 1 /* are all together at the end of the array. It returns the number */ 92 1 /* of non-zero elements back to the caller. */ 93 1 94 1 95 1 /* sort the array */ 96 1 97 1 sort_proc_mpid( proc_info, numproc ); 98 1 99 1 100 1 /* perform the addition */ 101 1 102 1 for( i = 0 ; j < numproc ; i = j ) 103 1 { 104 2 count += 1; 105 2 for( j = i + 1 ; j < numproc ; j++ ) 106 2 { 107 3 if( proc_info[i]->mpid != proc_info[j]->mpid ) break; 108 3 proc_info[i]->cputim += proc_info[j]->cputim; 109 3 if( !strlen( proc_info[i]->term ) ) 110 3 strcpy( proc_info[i]->term, proc_info[j]->term ); 111 3 zero_record( proc_info[j], length ); 112 3 } 113 2 ADD_BY_MPID 20-APR-1987 21:08:52 VAX C V2.2-015 Page 2 V1.0 20-APR-1987 21:08:46 [INTPROC$TIMEOUT]ADD_BY_MPID.C;59 (1) 114 2 115 2 /* check for exceptions and zero those records */ 116 2 117 2 if( exception( proc_info[i] ) ) 118 2 { 119 3 zero_record( proc_info[i], length ); 120 3 count -= 1; 121 3 } 122 2 } 123 1 124 1 /* sort the array again to clean up zeroed records */ 125 1 126 1 sort_proc_mpid( proc_info, numproc ); 127 1 return( count ); 128 1 } Command Line ------------ CC/SHOW=(INCLUDE,EXPANSION,INTERMEDIATE)/LIST/NOOPTIMIZE DC$ROOT:[INTPROC$TIMEOUT]ADD_BY_MPID.C;59/DIAGNOSTICS=DC$ROOT:[INTPROC$TIME OUT]ADD_BY_MPID.DIA;