Hi,
I'm trying to find a way to make some kind of monitor in C.
I found this but i get :
error: config.h: No such file or directory
error: glibtop.h: No such file or directory
error: glibtop/error.h: No such file or directory
error: glibtop/cpu.h: No such file or directory
error: glibtop_suid.h: No such file or directory

Can anyone help me with this?
Or to give me another idea like how to get info from /proc/cpuinfo with C ?
I'm using ubuntu 7.4

#include <stdio.h>
#include <glibtop.h>
#include <glibtop/cpu.h>
#include <glibtop/mem.h>
#include <glibtop/proclist.h>



int main(){

glibtop_init();

glibtop_cpu cpu;
glibtop_mem memory;
glibtop_proclist proclist;

glibtop_get_cpu (&cpu);
glibtop_get_mem(&memory);


printf("CPU TYPE INFORMATIONS \n\n"
"Cpu Total : %ld \n"
"Cpu User : %ld \n"
"Cpu Nice : %ld \n"
"Cpu Sys : %ld \n"
"Cpu Idle : %ld \n"
"Cpu Frequences : %ld \n",
(unsigned long)cpu.total,
(unsigned long)cpu.user,
(unsigned long)cpu.nice,
(unsigned long)cpu.sys,
(unsigned long)cpu.idle,
(unsigned long)cpu.frequency);

printf("\nMEMORY USING\n\n"
"Memory Total : %ld MB\n"
"Memory Used : %ld MB\n"
"Memory Free : %ld MB\n"
"Memory Buffered : %ld MB\n"
"Memory Cached : %ld MB\n"
"Memory user : %ld MB\n"
"Memory Locked : %ld MB\n",
(unsigned long)memory.total/(1024*1024),
(unsigned long)memory.used/(1024*1024),
(unsigned long)memory.free/(1024*1024),
(unsigned long)memory.shared/(1024*1024),
(unsigned long)memory.buffer/(1024*1024),
(unsigned long)memory.cached/(1024*1024),
(unsigned long)memory.user/(1024*1024),
(unsigned long)memory.locked/(1024*1024));

int which,arg;
glibtop_get_proclist(&proclist,which,arg);
printf("%ld\n%ld\n%ld\n",
(unsigned long)proclist.number,
(unsigned long)proclist.total,
(unsigned long)proclist.size);
return 0;
}

Recommended Answers

All 5 Replies

>>error: glibtop.h: No such file or directory
Either you don't have glib installed on your computer or you need to tell your compiler where to find it.

>>Or to give me another idea like how to get info from /proc/cpuinfo
Don't know, but someone else probably does.

Or to give me another idea like how to get info from /proc/cpuinfo

Sure: system("more /proc/cpuinfo > /tmp/file"); Now just open the file /tmp/file and read the data that you want.
Or you could use a named pipe with one end in your C-program and "more /proc/cpuinfo" in the other.
Or you could use if a filestream (C++) or..

glibtop.h is not part of glib - but a separate library called glibtop.

You need to install the glibtop library itself, and its header files.

On ubuntu/debian these correspond to the packages libgtop2 and libgtop2-dev so run:

apt-get install libgtop2 libgtop2-dev
as root.

I hope this helps.

taw

gcc systeminfo.c -o systeminfo -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libgtop-2.0 -lgtop-2.0 -lglib-2.0

compile the above code with this. for fedora red hat users..if libgtop not installed try su -c 'yum install libgtop2'

pls tell us hw to run it in Windows XP

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.