linux课程设计指导文档 联系客服

发布时间 : 星期一 文章linux课程设计指导文档更新完毕开始阅读b08d5cda7f1922791688e89f

相应的控件上:

QFile f(\

f.open(IO_ReadOnly);/*打开相应的文件*/

得到CPU的类型:(GenuinoIntel): QString *temp=new QString(buf); int from=temp->find(\int end=temp->find(\

QString *cpu_id=new QString(temp->mid(from+12,end-from-12));

同理,可得到cpu的名称(model name),主频(cpu MHZ),Cache的大小(cach size)

然后将其加载到相应的控件上:

cpuInfoLabel->setText(*cpu_id); cpunameLabel->setText(*cpu_name); frqLabel->setText(*cpu_mhz+\ cacheLabel->setText(*cpu_cache);

(2)

操作系统信息:

使用cat /proc/version可查看信息如下:

相应的代码如下: void mainForm::osinfo() {

int i;

char buf[400];

27

QFile f(\ f.open(IO_ReadOnly); for(i=0;i<400;i++){

buf[i]=f.getch();

}

/////////////////////////得到linux版本信息 QString *temp=new QString(buf); int from=temp->find(\ int end=temp->find(\ QString

QString(temp->mid(from+14,end-from-15));

/////////////////////////得到gcc版本信息 from=temp->find(\ end=temp->find(\

QString *gcc_version=new QString(temp->mid(from+11,end-from-13)); /*将信息加载到控件*/

osversionLabel->setText(*linux_version); gccLabel->setText(*gcc_version); }

(3)

内存信息:

*linux_version=new

使用cat /proc/meminfo可查看信息如下:

28

同理,可读取proc文件信息存入缓冲区: Memtotal:254876KB Memfree: 8172KB 由此可计算出主存已用空间和使用率 SwapTotal:530104kb SwapFree:530104kb 由此可计算交换区已用空间和使用率

而这些信息都是不断变化的,所有有设置定时器,不断地从文件中读取新的信息. 显示在界面上:

unused_mm_label->setText(*mem_free+\ all_mm_label->setText(*mem_total+\ all_swap->setText(*swap_total+\ free_swap->setText(*swap_free+\

int swap_use,mem_use;

swap_use=mem_total->toInt()-mem_free->toInt(); mem_use=swap_total->toInt()-swap_free->toInt();

29

textLabel17->setText(QString::number(swap_use,10)+\ textLabel18->setText(QString::number(mem_use,10)+\

int mem_useage,swap_useage; bool okok;

mem_useage=100-mem_free->toInt(&okok,10)*100/mem_total->toInt(&okok,10);

progressBar1->setProgress(mem_useage);

swap_useage=100-swap_free->toInt(&okok,10)*100/swap_total->toInt(&okok,10);

progressBar2->setProgress(swap_useage); }

(4)

进程信息:

当你进入/proc目录时,你会发现很多以十进制数为标题的目录,它们都是记录系统中正在运行的每个用户级进程的信息,数字表示进程号(pid)./proc/pid/stat目录下存储了该进程的相关信息。例如可用cat命令查看信息如下:

其中,1为进程的pid, init为进程名, S表明为睡眠进程, 16表示进程的优先级.

1785856为进程占用的内存大小, 即1785856B/1024=1748KB.

要获得进程信息,首先应该获得各进程的pid,将其存在一个qlist的缓冲区中: QDir qd(\

QStringList qslist=qd.entryList();

30