[TriLUG] Dual core question
Charles Fischer
fischer at 4pi.com
Fri May 20 14:47:56 EDT 2005
I would like to get a CPU core count from a Linux box. Does anybody have a
dual core box running a 2.6 kernel? If so would you run the following
short program and let me know what it output? I would also like to know
which version of Linux you are running and how many CPU sockets are filled
and the CPU model numbers. The program compiles with the following command
line:
cc cpu_core_check.c
and runs with the following:
./a.out
I am assuming that you copy the program from this e-mail and call it
cpu_core_check.c.
If somebody knows a better way to get a CPU and core count please let me know.
Thanks
Charles Fischer
#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
int main(int argc, char *argv[])
{
unsigned int len;
unsigned long mask;
int error;
int count = 0;
len = sizeof(unsigned long);
error = sched_getaffinity(0, len, &mask);
if (error != 0)
{
fprintf(stderr, "Error from sched_getaffinity.\n");
exit(-1);
}
while ((1 << count) & mask != 0) count++;
printf("CPU count: %d\n", count);
return(0);
}
More information about the TriLUG
mailing list