Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to obtain hardware/system information?

Status
Not open for further replies.

sedawk

Programmer
Feb 5, 2002
247
0
0
US
How can I obtain my computer's hardware configuration in C? for example, I want to know what CPU is using, COM port number, etc.
 
well, it depends on which platform u are in..

if u are working in a linux/solaris box then just do
man proc
or /proc.. its is a file-system that has all info pertaining
to the system and all the processes.
u can do sum programming on proc file-system.
(personally i wud use sum scripting language to extract the info ;-) )
iam sorry i have no idea abt windows.

Alternatively u can do a snmp walk on the system.. u can try this for remote systems also . but they must be running the snmp agent. u can get all info abt the system, its up-time , services and network info.
 
your answer is very funny:

I am saying to get information of computer hardware configuration information, it should be software independent, ie., no matter linux/unix or windows the configuration information should be retrieved. Besides, since the portability of C language, it should be a big deal over different operation system.

I think you are saying the utility function of operation systems. No, I don't mean that. I meant a C function can retract the information.
 
Lemme try to give u a "not-so-funny" answer (well atleast acc. 2 me )
as far as my "limited knowledge" of C and English goes
i think you are referring to a C library function..

FYI, these are the headers for the ANSI C lib.
<assert.h> : Diagnostics
<ctype.h> : Character Class Tests
<errno.h> : Error Codes Reported by (Some) Library Functions
<float.h> : Implementation-defined Floating-Point Limits
<limits.h> : Implementation-defined Limits
<locale.h> : Locale-specific Information
<math.h> : Mathematical Functions
<setjmp.h> : Non-local Jumps
<signal.h> : Signals
<stdarg.h> : Variable Argument Lists
<stddef.h> : Definitions of General Use
<stdio.h> : Input and Output
<stdlib.h> : Utility functions
<string.h> : String functions
<time.h> : Time and Date functions

Well using any of the functions in the C library to get the info u require.. the closest i can get is to use system and then based on the OS xtract d info..
if u are looking for a &quot;platform-independent&quot; way to get sys. info in C, I dont think the ANSI C library supports any such feature.

i think that perl and python offers support to get sys. info
but the necessary api/library have to be there

Hope this reply doesnt make u burst into laughter
 
This question always pops up at about this time of year. I assume someone sets it in a course. There are demos on how to get processor information in the freebie demo section on the installation disks for almost any language.

ANSI C cannot guaruntee to give you information such as COM ports, because ANSI C has to work for any computer, whether or not it actually has anything describable as a port. In fact it wouldn't be sensible even to put a &quot;name of processor&quot; function in ANSI C, because the language should be processor independant, and not all processors will provide a way to tell what they are. The methods of determining what processor you have in an IBM PC prior to pentium rely on devious tricks, because the processor ID op-code wasn't added until pentium. I'd imagine the situation is similar in other systems.
 
I recall long time ago, an C program(ANSI C) was using <dos.h> and some int21h(not sure the interruption number) to extract system information successfully. So I am pretty sure ANSI C can do this job successfully. The only problem is I couldn't remember how it was written. And it took me a long time to search the references.

I think someone here had experience in doing this with C.
 
hmmm... dos.h and int21 are ANSI C. Is that right? Doesn't seem like it should be.

-pete
 
Not that it matters since this forum isn't about ansi-c
exclusively.

I don't know anyone here who is going to pull magic
tricks with dos.h and inline assembly for you.
Also I thought you wanted this to be portable?
Not getting there with dos.h.

Take a look at the source code for hwinfo(linux),
or a project like cpu-z for windows.
Better yet take a gander at some of the opensource
alternative bios code(open bios, linux bios), for
an idea of how to query hardware and write platform
agnostic hardware accessing code.

 
dos.h is there in ANSI C [surprise]
well i guess u can find it in Turbo C.. iam pretty sure of that ..
 
Sorry, It's not ansi.c: no matter what gates wants us
to believe.


 
I am a little surprised to see so much ANSI confusion in a C forum. I would expect it in C++ forums but… ?

-pete
 
Yeah..doesn't make much sense does it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top