sysdep_HPUX.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C), 2000-2003 by Contributors to the monit codebase. 
00003  * All Rights Reserved.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License as
00007  * published by the Free Software Foundation; either version 2 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018  */
00019 
00020 
00021 #include <config.h>
00022 
00023 #ifdef HAVE_SYS_TYPES_H
00024 #include <sys/types.h>
00025 #endif
00026 
00027 #include <unistd.h>
00028 
00029 #ifdef HAVE_SYS_STAT_H
00030 #include <sys/stat.h>
00031 #endif
00032 
00033 #ifdef HAVE_FCNTL_H
00034 #include <fcntl.h>
00035 #endif
00036 
00037 #ifdef HAVE_STDLIB_H
00038 #include <stdlib.h>
00039 #endif
00040 
00041 #ifdef TIME_WITH_SYS_TIME
00042 #include <time.h>
00043 
00044 #ifdef HAVE_SYS_TIME_H
00045 #include <sys/time.h>
00046 #endif
00047 #else
00048 #include <time.h>
00049 #endif
00050 
00051 #ifdef HAVE_STRING_H
00052 #include <string.h>
00053 #endif
00054 
00055 #include <stdio.h>
00056 #include <strings.h>
00057 #include <sys/param.h>
00058 #define _RUSAGE_EXTENDED
00059 #include <sys/pstat.h>
00060 #include <nlist.h>
00061 #include <errno.h>
00062 
00063 #include "process.h"
00064 #include "sysdep.h"
00065 
00077 int init_process_info_sysdep(void) {
00078   struct pst_dynamic psd;
00079 
00080   if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) {
00081 
00082     num_cpus=psd.psd_proc_cnt;
00083 
00084   } else {
00085 
00086     return FALSE;
00087 
00088   }
00089 
00090   return TRUE;
00091 }
00092 
00093 
00094 int get_process_info_sysdep(ProcInfo_T p) {
00095 
00096   struct pst_status ps;
00097 
00098   if (pstat_getproc(&ps,sizeof(ps),(size_t)1,p->pid)==-1) {
00099 
00100     return FALSE;
00101 
00102   }
00103 
00104   /* jiffies -> seconds = 1 / HZ
00105      HZ is defined in "asm/param.h"  and it is usually 1/100s but on
00106      alpha system it is 1/1024s */
00107 
00108   p->cputime_prev = p->cputime;
00109   p->cputime =  ( ps.pst_utime + ps.pst_stime ) * 10 / HZ;
00110 
00111   if ( include_children ) {
00112 
00113     p->cputime += ( ps.pst_child_utime.pst_sec + ps.pst_child_stime.pst_sec ) * 10 / HZ;
00114 
00115   }
00116 
00117   /* first run ? */
00118 
00119   if ( p->time_prev == 0.0 ) {
00120 
00121       p->cputime_prev = p->cputime;
00122 
00123   }
00124 
00125   /* State is Zombie -> then we are a Zombie ... clear or? (-: */
00126 
00127   if ( ps.pst_stat || PS_ZOMBIE ) {
00128 
00129     p->status_flag |= PROCESS_ZOMBIE;
00130 
00131   }
00132 
00133   return TRUE;
00134 
00135 }
00136 
00137 /*
00138  * getloadavg (ave, n)
00139  *
00140  * This routine returns 'n' double precision floats containing
00141  * the load averages in 'ave'; at most 3 values will be returned.
00142  *
00143  * Return value: 0 if successful, -1 if failed (and all load
00144  * averages are returned as 0).
00145  */
00146 
00147 
00148 int getloadavg (double *a, int na) {
00149   
00150   struct pst_dynamic psd;
00151     
00152   if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) {
00153     
00154     switch (na) {
00155     case 3:
00156 
00157       a[2]=psd.psd_avg_15_min;
00158 
00159     case 2:
00160 
00161       a[1]=psd.psd_avg_5_min;
00162 
00163     case 1:
00164 
00165       a[0]=psd.psd_avg_1_min;
00166 
00167     }
00168 
00169   } else {
00170 
00171     return FALSE;
00172 
00173   }
00174 
00175   return TRUE;
00176 }