summaryrefslogtreecommitdiff
path: root/sysdeps/linux/cpu.c
diff options
context:
space:
mode:
authorMartin baulig <martin@home-of-linux.org>1998-07-03 17:19:25 +0000
committerMartin Baulig <martin@src.gnome.org>1998-07-03 17:19:25 +0000
commit9532dadc2e391e731be897d25e05a8123192e5fd (patch)
tree528a3d16122db1c5eb30720de6cb85df6867c92f /sysdeps/linux/cpu.c
parent94715ef7184e5aa1e8b66d1e4286cd373fa62a5b (diff)
downloadlibgtop-9532dadc2e391e731be897d25e05a8123192e5fd.tar.gz
No longer use `glibtop_machine.h' for Linux.
1998-07-03 Martin baulig <martin@home-of-linux.org> * macros/gnome-libgtop-sysdeps.m4: No longer use `glibtop_machine.h' for Linux. * sysdeps/linux/glibtop_machine.h: Removed. * sysdeps/guile/guile.awk: Using `scm_append' instead of `gh_append'. * sysdeps/guile/names/guile-names.awk: dito. * sysdeps/linux/*.c: Using code from stable branch again. * include/glibtop/parameter.h: New file. * lib/parameter.c: New file. * lib/{open, init}.c: Done some more work on server initialization
Diffstat (limited to 'sysdeps/linux/cpu.c')
-rw-r--r--sysdeps/linux/cpu.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/sysdeps/linux/cpu.c b/sysdeps/linux/cpu.c
index c6ce8976..750161a6 100644
--- a/sysdeps/linux/cpu.c
+++ b/sysdeps/linux/cpu.c
@@ -35,8 +35,7 @@ static const unsigned long _glibtop_sysdeps_cpu =
void
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
- char buffer [BUFSIZ], *tmp;
- int fd = 0, ret;
+ FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -44,25 +43,15 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
buf->flags = _glibtop_sysdeps_cpu;
- fd = open (FILENAME, O_RDONLY);
- if (fd == -1)
- glibtop_error_r (server, "open (%s): %s",
- FILENAME, strerror (errno));
+ f = fopen ("/proc/stat", "r");
+ if (!f) return;
- ret = read (fd, buffer, BUFSIZ);
- if (ret == -1)
- glibtop_error_r (server, "read (%s): %s",
- FILENAME, strerror (errno));
-
- tmp = skip_token (buffer); /* "cpu" */
-
- buf->user = strtoul (tmp, &tmp, 10);
- buf->nice = strtoul (tmp, &tmp, 10);
- buf->sys = strtoul (tmp, &tmp, 10);
- buf->idle = strtoul (tmp, &tmp, 10);
+ fscanf (f, "cpu %lu %lu %lu %lu\n",
+ &buf->user, &buf->nice, &buf->sys, &buf->idle);
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
buf->frequency = 100;
- close (fd);
+
+ fclose (f);
}