|
发表于 2003-9-28 10:53:17
|
显示全部楼层
回复: re
最初由 menglianjing 发表
/* 撼绦蛎? bserver */
/* 程序目的:观察LINUX行为 */
/* 程序作者:倩倩 */
#include <stdio.h>
#include <sys/time.h>
#include <getopt.h>
#include <stdlib.h>
#define BUF_SIZE 1024
const char *program_name;
void print_usage (FILE *stream, int exit_code)
{
fprintf(stream,"Usage:%s options\n",program_name);
fprintf(stream,"-h --help Display this usage information.\n");
exit(exit_code);
}
int main(int argc, char *argv[])
{
FILE procFile;
char lineBuf[BUF_SIZE];
struct timeval{
long tv_sec;
long tv_usec;
};
struct timeval tv;
int next_option;
const char *const short_options="h1:";
const struct option long_options[]={
{"help",1,NULL,'h'},
{"load",1,NULL,'1'},
{NULL,0,NULL,0}
};
program_name=argv[0];
/* 处理命令行参数 */
do
{
next_option=getopt_long(argc,argv,short_options,long_options,NULL);
switch(next_option) {
case 'h':
print_usage(stdout,0);
case '1':
break;
case '?':
print_usage(stderr,1);
case '-1':
break;
default:
abort();
}
}while (next_option!=-1);
/* 获取porc文件系统提供的信息 */
gettimeofday(&tv,NULL);
printf("内核初始报告 %s",ctime(&(tv.tv_sec)));
procFile=fopen("/proc/sys/kernel/hostname","r");
fgets(lineBuf,BUF_SIZE+1,procFile);
printf("主机名为: %s",lineBuf);
fclose(procFile);
return 0;
}
谢谢无双版主^-^,请多多指教。谢谢!!!也请大家多多指教。
这个程序的目的是检测CPU的类型和型号,所使用的LINUX内核版本,从系统最后一次启动以来已经经历了多长时间等等。
這裡欠了*
FILE procFile;
這個根本不用
struct timeval{
long tv_sec;
long tv_usec;
};
這個有什麼用? 看?硪彩菦]有用的東西 
default:
abort();
這是自己寫的嗎? 用kdevelop 吧,不錯的 |
|