Prisijungti

Alternatyva glibtop.h

TechtronicMindaugas N.
  • 3 Lie '13

Reikia alternatyvos glibtop.h (gnome-base/libgtop). Kuriu viena programa kuri skaiciuoja /proc/(d+)/stat, /proc/stat (kazkas panasaus i ps). Paciam pasirasyti ar skaiciuoti yra gana sudetinga, todel bandau rasti paprastesni buda. Gal jau kam teke kazka panasaus kurti ?

Taip atrodo programele kuri naudoja glibtop, ji man kaip example tinka, tik va rasyti i toki kaip serveri visa gnome yra kvailyste.

#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;
}

MakeFile:

CC=gcc
CFLAGS=-Wall -g
CLIBS=-lgtop-2.0 -lgtop_sysdeps-2.0 -lgtop_common-2.0

cpuinfo:cpu.c
$(CC) $(CFLAGS) systeminfo.c -o systeminfo $(CLIBS)
clean:
rm -f systeminfo

Kol kas bandau aiskintis kaip veikia pats ps (RTFS), bet tikiuosi sulaukti ir geresniu ideju, aciu.

TechtronicMindaugas N.
  • 3 Lie '13

Radau dar viena buda <sys/resource.h> getrusage() http://linux.die.net/man/2/getrusage anyway, laukiu geresniu ideju.

Atsakyti