/* * Copyright (C), 2000-2002 by Contributors to the monit codebase. * All Rights Reserved. * * 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 of the * License, 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 */ #include #ifdef HAVE_SYS_TYPES_H #include #endif #include #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef TIME_WITH_SYS_TIME #include #ifdef HAVE_SYS_TIME_H #include #endif #else #include #endif #ifdef HAVE_STRING_H #include #endif #include #include #include #define _RUSAGE_EXTENDED #include #include #include #include "process.h" #include "sysdep.h" /** * System dependent resource gathering code for HP/UX. * * @author Jan-Henrik Haukeland, * @author Christian Hopp * @author Joe Bryant * @version \$Id: sysdep_HPUX.c,v 1.1 2003/01/13 13:48:27 chopp Exp $ * * @file */ int init_process_info_sysdep(void) { struct pst_dynamic psd; if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) { num_cpus=psd.psd_proc_cnt; } else { return FALSE; } return TRUE; } int get_process_info_sysdep(ProcInfo_T p) { struct pst_status ps; if (pstat_getproc(&ps,sizeof(ps),(size_t)1,p->pid)==-1) { return FALSE; } /* jiffies -> seconds = 1 / HZ HZ is defined in "asm/param.h" and it is usually 1/100s but on alpha system it is 1/1024s */ p->cputime_prev = p->cputime; p->cputime = ( ps.pst_utime + ps.pst_stime ) * 10 / HZ; if ( include_children ) { p->cputime += ( ps.pst_child_utime.pst_sec + ps.pst_child_stime.pst_sec ) * 10 / HZ; } /* first run ? */ if ( p->time_prev == 0.0 ) { p->cputime_prev = p->cputime; } /* State is Zombie -> then we are a Zombie ... clear or? (-: */ if ( ps.pst_stat || PS_ZOMBIE ) { p->status_flag |= PROCESS_ZOMBIE; } return TRUE; } /* * getloadavg (ave, n) * * This routine returns 'n' double precision floats containing * the load averages in 'ave'; at most 3 values will be returned. * * Return value: 0 if successful, -1 if failed (and all load * averages are returned as 0). */ int getloadavg (double *a, int na) { struct pst_dynamic psd; if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) { switch (na) { case 3: a[2]=psd.psd_avg_15_min; case 2: a[1]=psd.psd_avg_5_min; case 1: a[0]=psd.psd_avg_1_min; } } else { return FALSE; } return TRUE; }