1 |
< |
/* |
1 |
> |
/* |
2 |
|
* i-scream central monitoring system |
3 |
< |
* http://www.i-scream.org.uk |
4 |
< |
* Copyright (C) 2000-2002 i-scream |
3 |
> |
* http://www.i-scream.org |
4 |
> |
* Copyright (C) 2000-2004 i-scream |
5 |
|
* |
6 |
< |
* This program is free software; you can redistribute it and/or |
7 |
< |
* modify it under the terms of the GNU General Public License |
8 |
< |
* as published by the Free Software Foundation; either version 2 |
9 |
< |
* of the License, or (at your option) any later version. |
6 |
> |
* This library is free software; you can redistribute it and/or |
7 |
> |
* modify it under the terms of the GNU Lesser General Public |
8 |
> |
* License as published by the Free Software Foundation; either |
9 |
> |
* version 2.1 of the License, or (at your option) any later version. |
10 |
|
* |
11 |
< |
* This program is distributed in the hope that it will be useful, |
11 |
> |
* This library is distributed in the hope that it will be useful, |
12 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
< |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
< |
* GNU General Public License for more details. |
13 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
> |
* Lesser General Public License for more details. |
15 |
|
* |
16 |
< |
* You should have received a copy of the GNU General Public License |
17 |
< |
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
16 |
> |
* You should have received a copy of the GNU Lesser General Public |
17 |
> |
* License along with this library; if not, write to the Free Software |
18 |
> |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
19 |
> |
* 02111-1307 USA |
20 |
> |
* |
21 |
> |
* $Id$ |
22 |
|
*/ |
23 |
|
|
24 |
|
#ifdef HAVE_CONFIG_H |
34 |
|
#include <string.h> |
35 |
|
#endif |
36 |
|
|
37 |
+ |
#include "tools.h" |
38 |
|
#ifdef SOLARIS |
39 |
|
#include <procfs.h> |
40 |
|
#include <limits.h> |
42 |
|
#define MAX_FILE_LENGTH PATH_MAX |
43 |
|
#endif |
44 |
|
#ifdef LINUX |
45 |
< |
#include "tools.h" |
42 |
< |
#include <linux/limits.h> |
45 |
> |
#include <limits.h> |
46 |
|
#define PROC_LOCATION "/proc" |
47 |
|
#define MAX_FILE_LENGTH PATH_MAX |
48 |
|
#endif |
49 |
< |
#ifdef FREEBSD |
49 |
> |
#ifdef ALLBSD |
50 |
|
#include <kvm.h> |
48 |
– |
#include <fcntl.h> |
51 |
|
#include <sys/param.h> |
52 |
|
#include <sys/sysctl.h> |
53 |
+ |
#endif |
54 |
+ |
#ifdef FREEBSD |
55 |
|
#include <sys/user.h> |
56 |
|
#endif |
57 |
|
|
71 |
|
#ifdef SOLARIS |
72 |
|
psinfo_t process_info; |
73 |
|
#endif |
74 |
< |
#ifdef FREEBSD |
74 |
> |
#ifdef ALLBSD |
75 |
|
struct kinfo_proc *kp_stats; |
76 |
< |
kvm_t *kvmd = NULL; |
76 |
> |
kvm_t *kvmd; |
77 |
|
int procs; |
78 |
|
#endif |
79 |
|
|
76 |
– |
#if defined(SOLARIS) || defined(LINUX) |
80 |
|
process_stat.sleeping=0; |
81 |
|
process_stat.running=0; |
82 |
|
process_stat.zombie=0; |
83 |
|
process_stat.stopped=0; |
84 |
|
process_stat.total=0; |
85 |
|
|
86 |
+ |
#if defined(SOLARIS) || defined(LINUX) |
87 |
|
if((proc_dir=opendir(PROC_LOCATION))==NULL){ |
88 |
|
return NULL; |
89 |
|
} |
138 |
|
} |
139 |
|
closedir(proc_dir); |
140 |
|
#endif |
141 |
< |
#ifdef FREEBSD |
142 |
< |
if((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL){ |
141 |
> |
#ifdef ALLBSD |
142 |
> |
if((kvmd = get_kvm()) == NULL){ |
143 |
|
return NULL; |
144 |
|
} |
145 |
|
|
146 |
|
kp_stats=kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &procs); |
147 |
|
|
148 |
|
while(procs--){ |
149 |
+ |
#ifdef FREEBSD5 |
150 |
+ |
if (kp_stats[procs].ki_stat == SSLEEP) process_stat.sleeping++; |
151 |
+ |
if (kp_stats[procs].ki_stat == SWAIT) process_stat.sleeping++; |
152 |
+ |
if (kp_stats[procs].ki_stat == SLOCK) process_stat.sleeping++; |
153 |
+ |
if (kp_stats[procs].ki_stat == SRUN) process_stat.running++; |
154 |
+ |
if (kp_stats[procs].ki_stat == SIDL) process_stat.running++; |
155 |
+ |
if (kp_stats[procs].ki_stat == SZOMB) process_stat.zombie++; |
156 |
+ |
if (kp_stats[procs].ki_stat == SSTOP) process_stat.stopped++; |
157 |
+ |
|
158 |
+ |
#else |
159 |
|
if (kp_stats[procs].kp_proc.p_stat == SSLEEP) process_stat.sleeping++; |
160 |
|
if (kp_stats[procs].kp_proc.p_stat == SRUN) process_stat.running++; |
161 |
|
if (kp_stats[procs].kp_proc.p_stat == SIDL) process_stat.running++; |
162 |
|
if (kp_stats[procs].kp_proc.p_stat == SZOMB) process_stat.zombie++; |
163 |
|
if (kp_stats[procs].kp_proc.p_stat == SSTOP) process_stat.stopped++; |
164 |
+ |
#endif |
165 |
|
} |
166 |
+ |
#endif |
167 |
|
|
168 |
< |
kvm_close(kvmd); |
168 |
> |
#ifdef CYGWIN |
169 |
> |
return NULL; |
170 |
|
#endif |
171 |
|
|
172 |
|
process_stat.total=process_stat.sleeping+process_stat.running+process_stat.zombie+process_stat.stopped; |
173 |
+ |
|
174 |
|
return &process_stat; |
175 |
|
} |