#include
#include
int main(void)
{
FILE* fp = NULL;
char *sp,*ep;
#define LINE_BUF_MAX 1024
char line_buf[LINE_BUF_MAX];
fp = fopen ("/proc/version", "r");
fgets(line_buf, LINE_BUF_MAX, fp);
sp = strstr(line_buf, "2.6.");
ep = strchr(sp, ' ');
*ep = 0;
printf("%s", sp);
}
luther@gliethttp:/vobs/tmp$ cat /proc/version
Linux version 2.6.27-7-generic (buildd@palmer) (gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu11) ) #1 SMP Tue Nov 4 19:33:20 UTC 2008
luther@gliethttp:/vobs/tmp$ gcc read_kernel_version.c
luther@gliethttp:/vobs/tmp$ ./a.out
2.6.27-7-genericluther@gliethttp:/vobs/tmp$
阅读(1595) | 评论(0) | 转发(0) |