4 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: os.c,v 1.18 2007/06/19 23:47:18 tbox Exp */
34 #if defined(_SC_NPROCESSORS_ONLN)
35 return sysconf((_SC_NPROCESSORS_ONLN
));
36 #elif defined(_SC_NPROC_ONLN)
37 return sysconf((_SC_NPROC_ONLN
));
43 #endif /* HAVE_SYSCONF */
48 #include <sys/pstat.h>
52 struct pst_dynamic psd
;
53 if (pstat_getdynamic(&psd
, sizeof(psd
), 1, 0) != -1)
54 return (psd
.psd_proc_cnt
);
61 #if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
62 #include <sys/types.h> /* for FreeBSD */
63 #include <sys/param.h> /* for NetBSD */
64 #include <sys/sysctl.h>
72 result
= sysctlbyname("hw.ncpu", &ncpu
, &len
, 0, 0);
85 #elif defined(HAVE_SYSCONF)
86 ncpus
= sysconf_ncpus();
88 #if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
90 ncpus
= sysctl_ncpus();
95 return ((unsigned int)ncpus
);