/[monit]/monit/process/common.c
ViewVC logotype

Diff of /monit/process/common.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by martinp, Tue Feb 11 21:27:40 2003 UTC revision 1.6 by chopp, Fri Jun 6 09:31:17 2003 UTC
# Line 63  Line 63 
63    
64    
65  #include "process.h"  #include "process.h"
66    #include "sysdep.h"
67    
68    
69  /**  /**
# Line 163  int get_process_info(ProcInfo_T p) { Line 164  int get_process_info(ProcInfo_T p) {
164    
165  }  }
166    
167    
168    
169    /**
170     * Write process data in processtree entry
171     * @param pid pid of the process
172     * @param entry process tree
173     * @return TRUE if succeeded otherwise FALSE.
174     */
175    int getdatafromproc(int pid, ProcessTree_T *entry) {
176    
177      ProcInfo_T pi=NEW(pi);
178    
179      pi->pid=pid;
180    
181      if (! get_process_info_sysdep(pi)) {
182    
183        return FALSE;
184    
185      }
186    
187      entry->pid=pid;
188      entry->mem_kbyte=pi->mem_kbyte;
189      entry->ppid=pi->ppid;
190    
191      free(pi);
192      return TRUE;
193    
194    }
195    
196    
197    /**
198     * Connects child and parent in a process treee
199     * @param parent pointer to parents process tree entry
200     * @param child pointer to childs process tree entry
201     * @return TRUE if succeeded otherwise FALSE.
202     */
203    int connectchild(ProcessTree_T * parent, ProcessTree_T * child) {
204    
205      ProcessTree_T ** tmp;
206    
207      ASSERT(child);
208      ASSERT(parent);
209    
210      if ( parent->pid == 0 || child->pid == 0 ) {
211    
212        return FALSE;
213        
214      }
215    
216      parent->children_num++;
217    
218      tmp = xcalloc(sizeof(ProcessTree_T *), parent->children_num);
219    
220      if ( parent->children != NULL ) {
221    
222        memcpy(tmp, parent->children, sizeof(ProcessTree_T *) * (parent->children_num - 1));
223        free(parent->children);
224    
225      }
226    
227      parent->children = (struct myprocesstree **) tmp;
228      parent->children[parent->children_num - 1] = (struct myprocesstree *) child;
229    
230      return TRUE;
231    
232    }
233    
234    
235    /**
236     * Fill data in the process tree by recusively walking through it
237     * @param pt process tree
238     * @return TRUE if succeeded otherwise FALSE.
239     */
240    void fillprocesstree(ProcessTree_T * pt) {
241    
242      int i;
243      ProcessTree_T  *parent_pt;
244    
245      ASSERT(pt);
246    
247      if ( pt->pid==0 ) {
248        
249        return;
250        
251      }
252    
253      pt->children_sum= pt->children_num;
254      pt->mem_kbyte_sum= pt->mem_kbyte;
255    
256      for( i = 0; i < pt->children_num; i++) {
257    
258        fillprocesstree(pt->children[i]);
259    
260      }
261    
262      if ( pt->parent != NULL ) {
263        
264        parent_pt=pt->parent;
265        parent_pt->children_sum+=pt->children_sum;
266        parent_pt->mem_kbyte_sum+=pt->mem_kbyte_sum;
267        
268      }
269    
270    }
271    
272    
273    /**
274     * Transfer child information from process tree to process info structre
275     * @param pi process info structure
276     * @param pt process tree
277     * @param treesize size of the process tree
278     * @return TRUE if succeeded otherwise FALSE.
279     */
280    int enterchildinfo(ProcInfo_T pi, ProcessTree_T * pt, int treesize) {
281    
282      ProcessTree_T  *leaf;
283    
284      leaf = findprocess(pi->pid, pt, treesize);
285    
286      if (NULL == (leaf = findprocess(pi->pid, pt, treesize))) {
287        
288        return FALSE;
289    
290      }
291      
292      pi->children = leaf->children_sum;
293      pi->total_mem_kbyte = leaf->mem_kbyte_sum;
294    
295      return TRUE;
296    
297    }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26