ProgrammingThis 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.
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.
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 ^_^
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.
"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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.