In Windows I read the registry key SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName
to get the full name and version of the OS.
But in Linux, the code
struct utsname ver;
uname(&ver);
retVal = ver.sysname;
returns the string linux
, not Ubuntu 9.04
.
How can I get the Linux distribution name and version?
Usually:
Not sure I followed exactly what you're after but I think you just want the "all" flag on uname:
trying this way is an interesting one and less restrictive than lsb-release.
/etc/os-release
is available on at least both CentOS 7 and Ubuntu 16.04, which makes it more cross-platform thanlsb_release
(not on CentOS) or/etc/system-release
(not on Ubuntu).Example:
on my system yields the following from the bash (terminal) prompt:
What's the purpose of getting that information?
If you're trying to detect some features or properties of the system (e.g. does it support some syscall or does it have some library), instead of relying on output of lsb_release you should either:
Note that the first way above applies even if your software is binary-only.
Some code examples:
You can even gracefully test for CPU opcodes support, read e.g. http://neugierig.org/software/chromium/notes/2009/12/flash-lahf.html , http://code.google.com/p/chromium/issues/detail?id=29789