Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cpu information

Tags:

c

linux

I want know how can we find cpu information (Number of cpus and spead of cpu) from c program in linux. can anybody help me onthat

like image 612
prameela Avatar asked Dec 21 '22 14:12

prameela


2 Answers

You can read from the /proc/cpuinfo file to gain information about CPUs in the running computer.

like image 74
Delan Azabani Avatar answered Jan 01 '23 14:01

Delan Azabani


As Delan has mentioned /proc/cpuinfo does provide those details.

There is also sysconf for getting the number of logical CPU's.

long numcpus = sysconf(_SC_NPROCESSORS_ONLN);
printf("Number of CPU's=%ld\n",numcpus);
like image 30
hookenz Avatar answered Jan 01 '23 15:01

hookenz