1 |
< |
/* |
1 |
> |
/* |
2 |
|
* i-scream central monitoring system |
3 |
|
* http://www.i-scream.org |
4 |
< |
* Copyright (C) 2000-2003 i-scream |
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 |
|
|
22 |
|
#ifdef HAVE_CONFIG_H |
32 |
|
#include <string.h> |
33 |
|
#endif |
34 |
|
|
35 |
+ |
#include "tools.h" |
36 |
|
#ifdef SOLARIS |
37 |
|
#include <procfs.h> |
38 |
|
#include <limits.h> |
40 |
|
#define MAX_FILE_LENGTH PATH_MAX |
41 |
|
#endif |
42 |
|
#ifdef LINUX |
43 |
< |
#include "tools.h" |
42 |
< |
#include <linux/limits.h> |
43 |
> |
#include <limits.h> |
44 |
|
#define PROC_LOCATION "/proc" |
45 |
|
#define MAX_FILE_LENGTH PATH_MAX |
46 |
|
#endif |
47 |
< |
#ifdef FREEBSD |
47 |
> |
#ifdef ALLBSD |
48 |
|
#include <kvm.h> |
48 |
– |
#include <fcntl.h> |
49 |
|
#include <sys/param.h> |
50 |
|
#include <sys/sysctl.h> |
51 |
+ |
#endif |
52 |
+ |
#ifdef FREEBSD |
53 |
|
#include <sys/user.h> |
54 |
|
#endif |
55 |
|
|
69 |
|
#ifdef SOLARIS |
70 |
|
psinfo_t process_info; |
71 |
|
#endif |
72 |
< |
#ifdef FREEBSD |
72 |
> |
#ifdef ALLBSD |
73 |
|
struct kinfo_proc *kp_stats; |
74 |
< |
kvm_t *kvmd = NULL; |
74 |
> |
kvm_t *kvmd; |
75 |
|
int procs; |
76 |
|
#endif |
77 |
|
|
136 |
|
} |
137 |
|
closedir(proc_dir); |
138 |
|
#endif |
139 |
< |
#ifdef FREEBSD |
140 |
< |
if((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL){ |
139 |
> |
#ifdef ALLBSD |
140 |
> |
if((kvmd = get_kvm()) == NULL){ |
141 |
|
return NULL; |
142 |
|
} |
143 |
|
|
146 |
|
while(procs--){ |
147 |
|
#ifdef FREEBSD5 |
148 |
|
if (kp_stats[procs].ki_stat == SSLEEP) process_stat.sleeping++; |
149 |
+ |
if (kp_stats[procs].ki_stat == SWAIT) process_stat.sleeping++; |
150 |
+ |
if (kp_stats[procs].ki_stat == SLOCK) process_stat.sleeping++; |
151 |
|
if (kp_stats[procs].ki_stat == SRUN) process_stat.running++; |
152 |
|
if (kp_stats[procs].ki_stat == SIDL) process_stat.running++; |
153 |
|
if (kp_stats[procs].ki_stat == SZOMB) process_stat.zombie++; |
154 |
|
if (kp_stats[procs].ki_stat == SSTOP) process_stat.stopped++; |
155 |
+ |
|
156 |
|
#else |
157 |
|
if (kp_stats[procs].kp_proc.p_stat == SSLEEP) process_stat.sleeping++; |
158 |
|
if (kp_stats[procs].kp_proc.p_stat == SRUN) process_stat.running++; |
161 |
|
if (kp_stats[procs].kp_proc.p_stat == SSTOP) process_stat.stopped++; |
162 |
|
#endif |
163 |
|
} |
164 |
+ |
#endif |
165 |
|
|
166 |
< |
kvm_close(kvmd); |
166 |
> |
#ifdef CYGWIN |
167 |
> |
return NULL; |
168 |
|
#endif |
169 |
|
|
170 |
|
process_stat.total=process_stat.sleeping+process_stat.running+process_stat.zombie+process_stat.stopped; |
171 |
+ |
|
172 |
|
return &process_stat; |
173 |
|
} |