Read linux kernel version using C?

后端 未结 6 802
花落未央
花落未央 2021-01-17 22:25

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

相关标签:
6条回答
  • 2021-01-17 23:00

    This should do:

    system("uname -r");
    

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

    0 讨论(0)
  • 2021-01-17 23:00

    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.

    0 讨论(0)
  • 2021-01-17 23:01

    You can use the uname() system call.

    0 讨论(0)
  • 2021-01-17 23:03

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

    0 讨论(0)
  • 2021-01-17 23:06

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

    0 讨论(0)
  • 2021-01-17 23:08

    You might want to try using the uname function.

    0 讨论(0)
提交回复
热议问题