sysdep_SOLARIS.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 <procfs.h>
00057 
00058 #include "process.h"
00059 #include "sysdep.h"
00060 
00073 int init_process_info_sysdep(void) {
00074 
00075   num_cpus= sysconf( _SC_NPROCESSORS_ONLN);
00076 
00077   return (getuid()==0);
00078 
00079 }
00080 
00081 double timestruc_to_tseconds(timestruc_t t) {
00082   return  t.tv_sec * 10 + t.tv_nsec / 100000000.0;
00083 }
00084 
00085 int get_process_info_sysdep(ProcInfo_T p) {
00086 
00087   char buf[4096];
00088   psinfo_t  * psinfo=  (psinfo_t *)&buf;
00089   pstatus_t * pstatus= (pstatus_t *)&buf;
00090 
00091   if (!read_proc_file(buf,4096, "psinfo", p->pid)) {
00092 
00093     return FALSE;
00094 
00095   }
00096 
00097   /* If we don't have any light-weight processes (LWP) then we
00098      are definitely a zombie */
00099 
00100   if ( psinfo->pr_nlwp == 0 ) {
00101 
00102     p->status_flag = PROCESS_ZOMBIE;
00103 
00104   }
00105 
00106 
00107   if ( p->status_flag != PROCESS_ZOMBIE ) {
00108     /* We can't access /proc/$pid/status of a zombie */
00109     /* and does it anyway matter? */
00110 
00111     p->mem_percent = psinfo->pr_pctmem * 1000 / 0x8000;
00112     p->mem_kbyte = psinfo->pr_rssize;
00113 
00114     if (!read_proc_file(buf,4096, "status", p->pid)) {
00115 
00116       return FALSE;
00117 
00118     }
00119 
00120     p->cputime_prev= p->cputime;
00121     p->cputime= ( timestruc_to_tseconds(pstatus->pr_utime) +
00122           timestruc_to_tseconds(pstatus->pr_stime) );
00123 
00124     if( include_children ) {
00125 
00126       p->cputime+= ( timestruc_to_tseconds(pstatus->pr_cutime) +
00127              timestruc_to_tseconds(pstatus->pr_cstime) );
00128 
00129     }
00130     /* first run ? */
00131 
00132     if ( p->time_prev == 0.0 ) {
00133 
00134       p->cputime_prev= p->cputime;
00135 
00136     }
00137 
00138   } else {
00139 
00140     p->cputime_prev= p->cputime = 0;
00141     p->mem_kbyte= 0;
00142     p->mem_percent= 0.0;
00143 
00144   }
00145 
00146   return TRUE;
00147 
00148 }