Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-06-2009, 08:05 AM   #1
LQ Newbie
Registered: Feb 2008
Distribution: RHEL
Posts: 13

Rep: Reputation: 0
Is there any C++ api available to know the OS description?

I am working tools that will be used on the multiple OS and platform. This tools will provide the details of the OS on which it is running, like 32 bit or 64 bit OS, exact version of Linux,Solaris,or other OS.

One way I am thinking of using the "uname -a" command to extract the OS information on the Linus/Unix based OS. Please suggest me that if it efficient to call the command from the program.

Please let me know if there is any api available or there is workaround I can implement.

Old 07-06-2009, 08:40 AM   #2
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,533

Rep: Reputation: 334Reputation: 334Reputation: 334Reputation: 334
You can consider using popen(), and then parse the results. Or under Linux, you can examine /proc/version and/or perhaps /proc/cpuinfo, to get information. Or just use "uname -a". I'm not sure if Solaris uses a similar /proc to that of Linux.

Here's a simple program:
#include <cstdio>
#include <iostream>
#include <string>
#include <fstream>

int main()
   // here, executing a command to get results via a pipe
   FILE* fp = popen("cat /proc/cpuinfo", "r");

   if (fp)
      char buf[1024] = {0};

      while (fgets(buf, sizeof(buf), fp))
         std::cout << buf;

   // here, just reading a file the ol' fashioned way
   std::fstream file("/proc/version", std::ios::in);

   if (file)
      std::string line;

      while (getline(file, line))
         std::cout << line << std::endl;

Last edited by dwhitney67; 07-06-2009 at 08:41 AM.
Old 07-06-2009, 09:04 AM   #3
Senior Member
Registered: May 2008
Posts: 3,711

Rep: Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148
As well as the command there's also a uname() function call.

'man 2 uname' for details.


api, c++, unix

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Sendmail description samd Linux - Software 4 07-09-2005 11:05 PM
logrotate description pharmhand02 Linux - Software 5 08-02-2004 09:18 AM
/etc/services description gmarais Linux - General 4 03-03-2004 04:10 AM
checkinstall description. e1000 Slackware 1 10-22-2003 12:48 AM
TripWire, need brief description Robert0380 Linux - Security 2 01-13-2003 09:25 AM

All times are GMT -5. The time now is 04:08 AM.

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