aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbhackerozzo <bhackerozzo@3b445381-d045-0410-9223-e17ecdb95f4b>2008-08-31 18:49:29 +0000
committerbhackerozzo <bhackerozzo@3b445381-d045-0410-9223-e17ecdb95f4b>2008-08-31 18:49:29 +0000
commitc7534b4eacfbc642f986d0039de7f757f6b5bcca (patch)
treee379ddf404bd83ef1f42b6e394ed05f4529e7fc2
parent229eaafc30e2bab864884702406ccc7ff5555674 (diff)
downloadcpulimit-c7534b4eacfbc642f986d0039de7f757f6b5bcca.tar.gz
simplified get_cpu_count()
-rw-r--r--cpulimit.c19
1 files changed, 1 insertions, 18 deletions
diff --git a/cpulimit.c b/cpulimit.c
index de0292b..031ef68 100644
--- a/cpulimit.c
+++ b/cpulimit.c
@@ -116,24 +116,7 @@ void *memrchr(const void *s, int c, size_t n)
//how many cpu do we have?
int get_cpu_count()
{
- int cpu_count = 0;
-#ifdef __linux__
- FILE *fd;
- char line[100];
- fd = fopen("/proc/stat", "r");
- if (fd < 0)
- return 0; //are we running Linux??
- while (fgets(line,sizeof(line),fd)!=NULL) {
- if (strncmp(line, "cpu", 3) != 0) break;
- cpu_count++;
- }
- fclose(fd);
- return cpu_count - 1;
-#elif defined __APPLE__
-//TODO: test sysconf(_SC_NPROCESSORS_ONLN), sysconf(_SC_NPROCESSORS_CONF)
- if (sysctlbyname("hw.ncpu",&cpu_count,sizeof(int),NULL,0)) return 1;
- return cpu_count;
-#endif
+ return sysconf(_SC_NPROCESSORS_ONLN);
}
//return t1-t2 in microseconds (no overflow checks, so better watch out!)
Un proyecto texto-plano.xyz