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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-06-2009, 08:05 AM
|
#1
|
|
LQ Newbie
Registered: Feb 2008
Distribution: RHEL
Posts: 13
Rep:
|
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
|
|
|
|
07-06-2009, 08:40 AM
|
#2
|
|
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,386
|
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 08:41 AM.
|
|
|
|
07-06-2009, 09:04 AM
|
#3
|
|
Senior Member
Registered: May 2008
Posts: 2,843
|
As well as the command there's also a uname() function call.
'man 2 uname' for details.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:35 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|