LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2009, 01:26 AM   #1
Renan_S2
Member
 
Registered: Jul 2007
Location: Santa Maria, Brazil
Distribution: Arch Linux
Posts: 66

Rep: Reputation: 16
How to get CPU information from within a C program?


Hello,

For an app I'm writing, I need to determine the CPU informations (manufacturer, model, architecture etc...). Essentially I need the same as /proc/cpuinfo gives, but in a way easier to use in a program, like a structure.

How to do that in a C program?

The architecture I can get with uname(2) function, e.g.


Code:
#include <stdio.h>
#include <sys/utsname.h>

int main() {
        struct utsname tmp;

        uname(&tmp);

        printf("%s",tmp.machine);
}

Thanks!
 
Old 08-29-2009, 02:46 AM   #2
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 366
Blog Entries: 1

Rep: Reputation: 44
Google for: /proc/cpuinfo c programming

First result.
 
Old 08-29-2009, 11:14 PM   #3
Renan_S2
Member
 
Registered: Jul 2007
Location: Santa Maria, Brazil
Distribution: Arch Linux
Posts: 66

Original Poster
Rep: Reputation: 16
Yep, that does it, I thought I needed some syscall.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getting cpu information 32/64 bit laucian Linux - Hardware 24 10-14-2013 03:23 PM
CPU and Memory information DavidDiggs Linux - Hardware 6 03-20-2008 08:36 PM
CPU information : how is it possible?? sachinh Linux - Server 6 06-06-2007 07:04 AM
CPU run information cygnus-x1 Other *NIX 3 05-15-2007 11:15 AM
CPU information structure alltime Programming 2 10-31-2005 05:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration