我写了C,在ubuntu上显示关于我的硬件的信息。现在,我想知道如何使它更加灵活,例如直接查询硬件而不是os更新的文件。因此,我想我可以查看写到/proc/scsi/scsi的内容,并做同样的工作,这样代码也可以在除了/proc/scsi/scsi之外的其他方法上工作,这样我就可以学习如何显示硬件信息。
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch, file_name[25] = "/proc/scsi/scsi";
FILE *fp;
fp = fopen(file_name,"r"); // read mode
if( fp == NULL )
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
printf("The contents of %s file are :\n", file_name);
while( ( ch = fgetc(fp) ) != EOF )
printf("%c",ch);
fclose(fp);
return 0;
}对我来说就像这样
$ cc driveinfo.c;./a.out
The contents of /proc/scsi/scsi file are :
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: WDC WD2500JS-75N Rev: 10.0
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: ST3250824AS Rev: 3.AD
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
Vendor: TSSTcorp Model: DVD+-RW TS-H653A Rev: D300
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi3 Channel: 00 Id: 00 Lun: 00
Vendor: Optiarc Model: DVD-ROM DDU1681S Rev: 102A
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
Vendor: Lexar Model: USB Flash Drive Rev: 1100
Type: Direct-Access ANSI SCSI revision: 00
Host: scsi5 Channel: 00 Id: 00 Lun: 00
Vendor: WD Model: 5000AAKB Externa Rev: l108
Type: Direct-Access ANSI SCSI revision: 00它能在其他的单品如bsd上运行吗?我怎样才能让它在ms-windows上运行呢?我可以直接查询硬件而不是/proc/scsi/scsi文件吗?
发布于 2013-03-06 14:25:52
/proc文件系统不是真实的,它是一个进入内核内部数据的视图,导出后看起来像文件。它存在于Linux和Solaris (这个想法被无耻地窃取的地方),可能还有其他Unixy系统。这种格式非常依赖于系统(甚至在Linux内核版本之间也发生了很大的变化)。
找出硬件数据并没有任何可移植的方法(也不可能,有些Unice和some运行在相当奇怪的铁板上)。
发布于 2013-03-06 13:59:50
/proc文件系统以Linux为中心,所以答案是否定的。BSD系统使用sysctl来处理这类信息。至于Windows,这不是最好的提问组,methinks。:)
https://unix.stackexchange.com/questions/67040
复制相似问题