LinuxQuestions.org
Register a domain and help support LQ
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 07-06-2009, 09:05 AM   #1
matrixdipu
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.

TIA
dipu
 
Old 07-06-2009, 09:40 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
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:
Code:
#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;
      }
      pclose(fp);
   }


   // 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 09:41 AM.
 
Old 07-06-2009, 10:04 AM   #3
GazL
Senior Member
 
Registered: May 2008
Posts: 3,502

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

'man 2 uname' for details.
 
  


Reply

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


All times are GMT -5. The time now is 05:47 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration