LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
 
LinkBack Search this Thread
Old 05-10-2006, 10:22 PM   #1
TioDuke
LQ Newbie
 
Registered: May 2006
Location: Canada
Distribution: SuSE Linux
Posts: 4

Rep: Reputation: 0
Reading Linux' version string


Hi,

I am trying to access Linux' version info from a CLI program. All I want to do is to output a version string (kernel version would just be enough, distro name: nice to have but not necessary).

I have no idea how to achieve this. I took a look at system.h, but as I imagined it is not there. I am hoping I won't have to do a popen()/fgets()/pclose() on some command that will output the version string. I thought of using getenv() to read the info from the environment, but a "export -p" did not output any env. variable with the version information.

Any help will he highly appreciated.

Thank you very much. Sergio.
 
Old 05-11-2006, 12:10 AM   #2
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Well, the command "uname -rs" would return both the release and the system name (read more about uname command here). A simple solution would be to use "system" and run that uname command inside it... Not the best solution, but definitely the easiest ^_^
 
Old 05-11-2006, 12:27 AM   #3
Vagrant
Member
 
Registered: Nov 2001
Posts: 75

Rep: Reputation: 15
Quote:
Originally Posted by Mega Man X
Well, the command "uname -rs" would return both the release and the system name (read more about uname command here). A simple solution would be to use "system" and run that uname command inside it... Not the best solution, but definitely the easiest ^_^

I can't remember off-hand which one it is, but this information is in a kernel header file.
 
Old 05-11-2006, 12:27 AM   #4
David the H.
Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 5,339

Rep: Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202
"cat /proc/version" gives me my kernel, gcc, and distro versions. I have no idea if it's universal across distros though.
 
Old 05-11-2006, 01:09 AM   #5
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 33
Use the uname(2) call. It works on most Unix systems.
 
Old 05-11-2006, 11:23 AM   #6
TioDuke
LQ Newbie
 
Registered: May 2006
Location: Canada
Distribution: SuSE Linux
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you everyone for your quick answers.

I am using now the uname(2) call (because I don't need to do the popen/fgets/pclose thing) and it is working just fine.

Thank you again. Sergio.

Last edited by TioDuke; 05-11-2006 at 11:26 AM.
 
Old 05-11-2006, 11:29 AM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,371

Rep: Reputation: Disabled
Quote:
Originally Posted by David the H.
"cat /proc/version" gives me my kernel, gcc, and distro versions. I have no idea if it's universal across distros though.
I think this is a pretty standard file, given that /proc is standard at least. Also, the version of GCC it shows is the one used to build the kernel AFAIK, which may differ from the one that's installed on your system.
 
Old 05-11-2006, 11:43 PM   #8
David the H.
Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 5,339

Rep: Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202
Thank you Nylex. The main reason I mentioned it is because it's the only place I know of that mentions the actual distro name. But since that string would have to be included by the distribution's manager, I can't believe that it's universal. I imagine it would have to be applied as a kernel patch, so anyone running a vanilla kernel.org kernel, for example, would likely not have that info.
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading a char string of variable size in C introuble Programming 3 05-08-2005 01:07 PM
Parse RPM version string in Bash jimwelc Linux - Newbie 1 02-28-2005 05:22 PM
Is there any benefit to spoofing SSH version string, and how do I do that? Steve Cronje Linux - Security 2 01-19-2005 05:17 PM
reading in string with fgets bostonbanana Programming 4 12-12-2004 02:10 PM
setting version string linuxdev Linux - Newbie 1 02-13-2004 09:35 AM


All times are GMT -5. The time now is 05:09 AM.

Main Menu
 
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
Open Source Consulting | Domain Registration