9

I am using Ubuntu and I want to read the version of its kernel. I found a file named version in /proc/ that records the version of the current kernel.

If I dont want to read file, is there any other way, like built-in function in C, that I can read the version in C?

Thanks

jschmier
  • 15,458
  • 6
  • 54
  • 72
ipkiss
  • 13,311
  • 33
  • 88
  • 123

6 Answers6

22

You can use the uname() system call.

Unknown
  • 5,722
  • 5
  • 43
  • 64
10

Check the uname function. It gives you a lot of information without the need to parse output of some linux executables.

INS
  • 10,594
  • 7
  • 58
  • 89
7

You might want to try using the uname function.

icktoofay
  • 126,289
  • 21
  • 250
  • 231
0

This should do:

system("uname -r");

EDIT: type man uname in a terminal to get the list of options you can use with uname

nico
  • 50,859
  • 17
  • 87
  • 112
0

Or you can read /proc/version, but this is not as good as calling uname(2) directly. uname(2) is more natural to C.

Cong Wang
  • 2,001
  • 12
  • 13
-1

Look at this article for the shell based way of getting kernel information. You can suitably run all of this using the system() call. But I am assuming that wouldn't be enough in your case. You'd need someway to parse the shell output. Hence make use of popen() call.

Community
  • 1
  • 1
deostroll
  • 11,661
  • 21
  • 90
  • 161