The code in this directory fetches all information directly from the
1998-06-13 Martin Baulig <martin@home-of-linux.org> The code in this directory fetches all information directly from the kernel. It uses the new table () system call from the `kernel' directory.
This commit is contained in:
committed by
Martin Baulig
parent
eedc64096c
commit
c60d1d5449
28
sysdeps/kernel/.cvsignore
Normal file
28
sysdeps/kernel/.cvsignore
Normal file
@@ -0,0 +1,28 @@
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
close.lo
|
||||
cpu.lo
|
||||
init.lo
|
||||
ipc_limits.lo
|
||||
libgtop_sysdeps.la
|
||||
loadavg.lo
|
||||
mem.lo
|
||||
msg_limits.lo
|
||||
open.lo
|
||||
procdata.lo
|
||||
prockernel.lo
|
||||
proclist.lo
|
||||
procmem.lo
|
||||
procsegment.lo
|
||||
procsignal.lo
|
||||
procstate.lo
|
||||
proctime.lo
|
||||
procuid.lo
|
||||
sem_limits.lo
|
||||
shm_limits.lo
|
||||
swap.lo
|
||||
sysdeps.lo
|
||||
sysinfo.lo
|
||||
uptime.lo
|
5
sysdeps/kernel/ChangeLog
Normal file
5
sysdeps/kernel/ChangeLog
Normal file
@@ -0,0 +1,5 @@
|
||||
1998-06-13 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
The code in this directory fetches all information
|
||||
directly from the kernel. It uses the new table ()
|
||||
system call from the `kernel' directory.
|
17
sysdeps/kernel/Makefile.am
Normal file
17
sysdeps/kernel/Makefile.am
Normal file
@@ -0,0 +1,17 @@
|
||||
LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
|
||||
-I$(top_srcdir)/include -I$(top_srcdir)/intl @GUILE_INCS@ \
|
||||
-DGTOPLOCALEDIR=\"$(datadir)/locale\" -D_GNU_SOURCE
|
||||
|
||||
CFLAGS = -Wall -W @CFLAGS@
|
||||
|
||||
lib_LTLIBRARIES = libgtop_sysdeps.la
|
||||
|
||||
libgtop_sysdeps_la_SOURCES = init.c open.c close.c cpu.c mem.c swap.c \
|
||||
uptime.c loadavg.c shm_limits.c msg_limits.c \
|
||||
sem_limits.c proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c
|
||||
|
||||
include_HEADERS = glibtop_server.h
|
28
sysdeps/kernel/close.c
Normal file
28
sysdeps/kernel/close.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop/close.h>
|
||||
|
||||
/* Closes pipe to gtop server. */
|
||||
|
||||
void
|
||||
glibtop_close_l (glibtop *server)
|
||||
{ }
|
55
sysdeps/kernel/cpu.c
Normal file
55
sysdeps/kernel/cpu.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/cpu.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu =
|
||||
(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) +
|
||||
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
|
||||
(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
|
||||
|
||||
/* Provides information about cpu usage. */
|
||||
|
||||
void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
if (table (TABLE_CPU, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_CPU): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
buf->total = tbl.cpu.total;
|
||||
buf->user = tbl.cpu.user;
|
||||
buf->nice = tbl.cpu.nice;
|
||||
buf->sys = tbl.cpu.sys;
|
||||
buf->idle = tbl.cpu.idle;
|
||||
buf->frequency = tbl.cpu.frequency;
|
||||
}
|
46
sysdeps/kernel/glibtop_server.h
Normal file
46
sysdeps/kernel/glibtop_server.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef __GLIBTOP_SERVER_H__
|
||||
#define __GLIBTOP_SERVER_H__
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define GLIBTOP_SUID_CPU 0
|
||||
#define GLIBTOP_SUID_MEM 0
|
||||
#define GLIBTOP_SUID_SWAP 0
|
||||
#define GLIBTOP_SUID_UPTIME 0
|
||||
#define GLIBTOP_SUID_LOADAVG 0
|
||||
#define GLIBTOP_SUID_SHM_LIMITS 0
|
||||
#define GLIBTOP_SUID_MSG_LIMITS 0
|
||||
#define GLIBTOP_SUID_SEM_LIMITS 0
|
||||
#define GLIBTOP_SUID_PROCLIST 0
|
||||
#define GLIBTOP_SUID_PROC_STATE 0
|
||||
#define GLIBTOP_SUID_PROC_UID 0
|
||||
#define GLIBTOP_SUID_PROC_MEM 0
|
||||
#define GLIBTOP_SUID_PROC_TIME 0
|
||||
#define GLIBTOP_SUID_PROC_SIGNAL 0
|
||||
#define GLIBTOP_SUID_PROC_KERNEL 0
|
||||
#define GLIBTOP_SUID_PROC_SEGMENT 0
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
44
sysdeps/kernel/init.c
Normal file
44
sysdeps/kernel/init.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/open.h>
|
||||
|
||||
static glibtop _glibtop_global_server;
|
||||
glibtop *glibtop_global_server = NULL;
|
||||
|
||||
glibtop *
|
||||
glibtop_init_r (glibtop **server, const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
if (*server != NULL)
|
||||
return *server;
|
||||
|
||||
fprintf (stderr, "DEBUG: %s (%d)\n", __FILE__, __LINE__);
|
||||
|
||||
if (glibtop_global_server == NULL) {
|
||||
glibtop_global_server = &_glibtop_global_server;
|
||||
glibtop_open_r (glibtop_global_server, "glibtop",
|
||||
features, flags);
|
||||
}
|
||||
|
||||
return *server = glibtop_global_server;
|
||||
}
|
38
sysdeps/kernel/kernel.h
Normal file
38
sysdeps/kernel/kernel.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef __GLIBTOP_KERNEL_KERNEL_H__
|
||||
#define __GLIBTOP_KERNEL_KERNEL_H__
|
||||
|
||||
#include <linux/unistd.h>
|
||||
#include <linux/table.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <syscall.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern int table (int, union table *, const void *);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
57
sysdeps/kernel/loadavg.c
Normal file
57
sysdeps/kernel/loadavg.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/loadavg.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_loadavg =
|
||||
(1 << GLIBTOP_LOADAVG_LOADAVG);
|
||||
|
||||
/* Provides load load averange. */
|
||||
|
||||
void
|
||||
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_loadavg));
|
||||
|
||||
if (table (TABLE_LOADAVG, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_LOADAVG): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_loadavg;
|
||||
|
||||
#if 0
|
||||
fprintf (stderr, "Table (%u) = (%lu, %lu, %lu) - %u, %u, %u\n",
|
||||
TABLE_LOADAVG, tbl.loadavg.loadavg [0], tbl.loadavg.loadavg [1],
|
||||
tbl.loadavg.loadavg [2], tbl.loadavg.nr_running,
|
||||
tbl.loadavg.nr_tasks, tbl.loadavg.last_pid);
|
||||
#endif
|
||||
|
||||
buf->loadavg [0] = tbl.loadavg.loadavg [0];
|
||||
buf->loadavg [1] = tbl.loadavg.loadavg [1];
|
||||
buf->loadavg [2] = tbl.loadavg.loadavg [2];
|
||||
}
|
58
sysdeps/kernel/mem.c
Normal file
58
sysdeps/kernel/mem.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/mem.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_mem =
|
||||
(1 << GLIBTOP_MEM_TOTAL) + (1 << GLIBTOP_MEM_USED) +
|
||||
(1 << GLIBTOP_MEM_FREE) + (1 << GLIBTOP_MEM_SHARED) +
|
||||
(1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED) +
|
||||
(1 << GLIBTOP_MEM_USER);
|
||||
|
||||
/* Provides information about memory usage. */
|
||||
|
||||
void
|
||||
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_mem));
|
||||
|
||||
if (table (TABLE_MEM, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_MEM): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_mem;
|
||||
|
||||
buf->total = tbl.mem.total;
|
||||
buf->used = tbl.mem.used;
|
||||
buf->free = tbl.mem.free;
|
||||
buf->shared = tbl.mem.shared;
|
||||
buf->buffer = tbl.mem.buffer;
|
||||
buf->cached = tbl.mem.cached;
|
||||
|
||||
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
|
||||
}
|
55
sysdeps/kernel/msg_limits.c
Normal file
55
sysdeps/kernel/msg_limits.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop/msg_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_msg_limits =
|
||||
(1 << GLIBTOP_IPC_MSGPOOL) + (1 << GLIBTOP_IPC_MSGMAP) +
|
||||
(1 << GLIBTOP_IPC_MSGMAX) + (1 << GLIBTOP_IPC_MSGMNB) +
|
||||
(1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) +
|
||||
(1 << GLIBTOP_IPC_MSGTQL);
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
|
||||
{
|
||||
struct msginfo msginfo;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_msg_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_msg_limits;
|
||||
|
||||
msgctl (0, IPC_INFO, (struct msqid_ds *) &msginfo);
|
||||
|
||||
buf->msgpool = msginfo.msgpool;
|
||||
buf->msgmap = msginfo.msgmap;
|
||||
buf->msgmax = msginfo.msgmax;
|
||||
buf->msgmnb = msginfo.msgmnb;
|
||||
buf->msgmni = msginfo.msgmni;
|
||||
buf->msgssz = msginfo.msgssz;
|
||||
buf->msgtql = msginfo.msgtql;
|
||||
}
|
62
sysdeps/kernel/open.c
Normal file
62
sysdeps/kernel/open.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop/open.h>
|
||||
|
||||
/* =====================================================
|
||||
* Linux kernel version information for procps utilities
|
||||
* Copyright (c) 1996 Charles Blake <cblake@bbn.com>
|
||||
*/
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
static int linux_version_code = 0;
|
||||
|
||||
static void set_linux_version(void) {
|
||||
static struct utsname uts;
|
||||
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
|
||||
|
||||
if (linux_version_code) return;
|
||||
if (uname(&uts) == -1) /* failure most likely implies impending death */
|
||||
exit(1);
|
||||
if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3)
|
||||
fprintf(stderr, /* *very* unlikely to happen by accident */
|
||||
"Non-standard uts for running kernel:\n"
|
||||
"release %s=%d.%d.%d gives version code %d\n",
|
||||
uts.release, x, y, z, LINUX_VERSION(x,y,z));
|
||||
linux_version_code = LINUX_VERSION(x, y, z);
|
||||
}
|
||||
|
||||
/* ======================================================= */
|
||||
|
||||
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
|
||||
|
||||
void
|
||||
glibtop_open_r (glibtop *server, const char *program_name,
|
||||
const unsigned long features, const unsigned flags)
|
||||
{
|
||||
memset (server, 0, sizeof (glibtop));
|
||||
server->name = program_name;
|
||||
|
||||
set_linux_version ();
|
||||
server->os_version_code = (unsigned long) linux_version_code;
|
||||
}
|
178
sysdeps/kernel/procdata.c
Normal file
178
sysdeps/kernel/procdata.c
Normal file
@@ -0,0 +1,178 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/procdata.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
#define BIT_SHIFT(x) (1 << (x % 32))
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_procdata_0 =
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CMD) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_STATE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_UID) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_PID) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_PPID) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_PGRP) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SESSION) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_TTY) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_TPGID) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_PRIORITY) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_NICE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SIGNAL) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_BLOCKED) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SIGIGNORE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SIGCATCH) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_START_TIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_UTIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_STIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CUTIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CSTIME) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SIZE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_RESIDENT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_SHARE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_TRS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_LRS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_DRS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_DT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_VSIZE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_RSS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_RSS_RLIM) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_TIMEOUT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_IT_REAL_VALUE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_procdata_1 =
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_K_FLAGS) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_MIN_FLT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_MAJ_FLT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CMIN_FLT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_CMAJ_FLT) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_START_CODE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_END_CODE) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_START_STACK) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_ESP) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_KSTK_EIP) +
|
||||
BIT_SHIFT(GLIBTOP_PROCDATA_WCHAN);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_procdata_s (glibtop *server, glibtop_procdata *buf, pid_t pid)
|
||||
{
|
||||
char input [BUFSIZ], *tmp;
|
||||
struct stat statb;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_procdata));
|
||||
|
||||
if (pid == 0) {
|
||||
/* Client is only interested in the flags. */
|
||||
buf->flags [0] = _glibtop_sysdeps_procdata_0;
|
||||
buf->flags [1] = _glibtop_sysdeps_procdata_1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
if (stat (input, &statb)) return;
|
||||
|
||||
buf->uid = statb.st_uid;
|
||||
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
memset (buf->cmd, 0, sizeof (buf->cmd));
|
||||
sscanf (input, "%d (%39c", &buf->pid, buf->cmd);
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
"%c %d %d %d %d %d %lu %lu %lu %lu %lu "
|
||||
"%ld %ld %ld %ld %d %d %lu %lu %ld %lu "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %d %d %d %d %lu",
|
||||
&buf->state, &buf->ppid, &buf->pgrp, &buf->session,
|
||||
&buf->tty, &buf->tpgid, &buf->k_flags, &buf->min_flt,
|
||||
&buf->cmin_flt, &buf->maj_flt, &buf->cmaj_flt,
|
||||
&buf->utime, &buf->stime, &buf->cutime, &buf->cstime,
|
||||
&buf->priority, &buf->nice, &buf->timeout,
|
||||
&buf->it_real_value, &buf->start_time, &buf->vsize,
|
||||
&buf->rss, &buf->rss_rlim, &buf->start_code,
|
||||
&buf->end_code, &buf->start_stack, &buf->kstk_esp,
|
||||
&buf->kstk_eip, &buf->signal, &buf->blocked,
|
||||
&buf->sigignore, &buf->sigcatch, &buf->wchan);
|
||||
|
||||
if (buf->tty == 0)
|
||||
/* the old notty val, update elsewhere bef. moving to 0 */
|
||||
buf->tty = -1;
|
||||
|
||||
if (server->os_version_code < LINUX_VERSION(1,3,39)) {
|
||||
/* map old meanings to new */
|
||||
buf->priority = 2*15 - buf->priority;
|
||||
buf->nice = 15 - buf->nice;
|
||||
}
|
||||
if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
|
||||
/* when tty wasn't full devno */
|
||||
buf->tty = 4*0x100 + buf->tty;
|
||||
|
||||
fclose (f);
|
||||
|
||||
sprintf (input, "/proc/%d/statm", pid);
|
||||
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
sscanf (input, "%ld %ld %ld %ld %ld %ld %ld",
|
||||
&buf->size, &buf->resident, &buf->share,
|
||||
&buf->trs, &buf->lrs, &buf->drs, &buf->dt);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags [0] = _glibtop_sysdeps_procdata_0;
|
||||
buf->flags [1] = _glibtop_sysdeps_procdata_1;
|
||||
}
|
63
sysdeps/kernel/prockernel.c
Normal file
63
sysdeps/kernel/prockernel.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/prockernel.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel =
|
||||
(1 << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1 << GLIBTOP_PROC_KERNEL_MIN_FLT) +
|
||||
(1 << GLIBTOP_PROC_KERNEL_MAJ_FLT) + (1 << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
|
||||
(1 << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1 << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
|
||||
(1 << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1 << GLIBTOP_PROC_KERNEL_WCHAN);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
||||
|
||||
if (pid == 0) {
|
||||
/* Client is only interested in the flags. */
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
return;
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_KERNEL, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_KERNEL): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
|
||||
buf->min_flt = tbl.proc_kernel.min_flt;
|
||||
buf->cmin_flt = tbl.proc_kernel.cmin_flt;
|
||||
buf->maj_flt = tbl.proc_kernel.maj_flt;
|
||||
buf->cmaj_flt = tbl.proc_kernel.cmaj_flt;
|
||||
buf->kstk_esp = tbl.proc_kernel.kesp;
|
||||
buf->kstk_eip = tbl.proc_kernel.keip;
|
||||
buf->wchan = tbl.proc_kernel.wchan;
|
||||
}
|
155
sysdeps/kernel/proclist.c
Normal file
155
sysdeps/kernel/proclist.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/proclist.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proclist =
|
||||
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
|
||||
(1 << GLIBTOP_PROCLIST_SIZE);
|
||||
|
||||
#define BLOCK_COUNT 256
|
||||
#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned))
|
||||
|
||||
/* Fetch list of currently running processes.
|
||||
*
|
||||
* The interface of this function is a little bit different from the others:
|
||||
* buf->flags is only set if the call succeeded, in this case pids_chain,
|
||||
* a list of the pids of all currently running processes is returned,
|
||||
* buf->number is the number of elements of this list and buf->size is
|
||||
* the size of one single element (sizeof (unsigned)). The total size is
|
||||
* stored in buf->total.
|
||||
*
|
||||
* The calling function has to free the memory to which a pointer is returned.
|
||||
*
|
||||
* On error, NULL is returned and buf->flags is zero. */
|
||||
|
||||
unsigned *
|
||||
glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
|
||||
{
|
||||
DIR *proc;
|
||||
struct dirent *entry;
|
||||
char buffer [BUFSIZ];
|
||||
unsigned count, total, pid;
|
||||
unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
|
||||
unsigned pids_size = 0, pids_offset = 0, new_size;
|
||||
struct stat statb;
|
||||
int len, i, ok;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proclist));
|
||||
|
||||
proc = opendir ("/proc");
|
||||
if (!proc) return NULL;
|
||||
|
||||
/* read every every entry in /proc */
|
||||
|
||||
for (count = total = 0, entry = readdir (proc); entry; entry = readdir (proc)) {
|
||||
ok = 1; len = strlen (entry->d_name);
|
||||
|
||||
/* does it consist entirely of digits? */
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (!isdigit (entry->d_name [i])) ok = 0;
|
||||
if (!ok) continue;
|
||||
|
||||
/* convert it in a number */
|
||||
|
||||
if (sscanf (entry->d_name, "%u", &pid) != 1) continue;
|
||||
|
||||
/* is it really a directory? */
|
||||
|
||||
sprintf (buffer, "/proc/%d", pid);
|
||||
|
||||
if (stat (buffer, &statb)) continue;
|
||||
|
||||
if (!S_ISDIR (statb.st_mode)) continue;
|
||||
|
||||
/* Fine. Now we first try to store it in pids. If this buffer is
|
||||
* full, we copy it to the pids_chain. */
|
||||
|
||||
if (count >= BLOCK_COUNT) {
|
||||
/* The following call to glibtop_realloc will be equivalent to
|
||||
* glibtop_malloc if pids_chain is NULL. We just calculate the
|
||||
* new size and copy pids to the beginning of the newly allocated
|
||||
* block. */
|
||||
|
||||
new_size = pids_size + BLOCK_SIZE;
|
||||
|
||||
pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
|
||||
|
||||
memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE);
|
||||
|
||||
pids_size = new_size;
|
||||
|
||||
pids_offset += BLOCK_COUNT;
|
||||
|
||||
count = 0;
|
||||
}
|
||||
|
||||
/* pids is now big enough to hold at least one single pid. */
|
||||
|
||||
pids [count++] = pid;
|
||||
|
||||
total++;
|
||||
}
|
||||
|
||||
closedir (proc);
|
||||
|
||||
/* count is only zero if an error occured (one a running Linux system, we
|
||||
* only have at least one single process). */
|
||||
|
||||
if (!count) return NULL;
|
||||
|
||||
/* The following call to glibtop_realloc will be equivalent to
|
||||
* glibtop_malloc if pids_chain is NULL. We just calculate the
|
||||
* new size and copy pids to the beginning of the newly allocated
|
||||
* block. */
|
||||
|
||||
new_size = pids_size + count * sizeof (unsigned);
|
||||
|
||||
pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
|
||||
|
||||
memcpy (pids_chain + pids_offset, pids, count * sizeof (unsigned));
|
||||
|
||||
pids_size = new_size;
|
||||
|
||||
pids_offset += BLOCK_COUNT;
|
||||
|
||||
/* Since everything is ok now, we can set buf->flags, fill in the remaining fields
|
||||
and return pids_chain. */
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proclist;
|
||||
|
||||
buf->size = sizeof (unsigned);
|
||||
buf->number = total;
|
||||
|
||||
buf->total = total * sizeof (unsigned);
|
||||
|
||||
return pids_chain;
|
||||
}
|
65
sysdeps/kernel/procmem.c
Normal file
65
sysdeps/kernel/procmem.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procmem.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
(1 << GLIBTOP_PROC_MEM_SIZE) + (1 << GLIBTOP_PROC_MEM_VSIZE) +
|
||||
(1 << GLIBTOP_PROC_MEM_RESIDENT) + (1 << GLIBTOP_PROC_MEM_SHARE) +
|
||||
(1 << GLIBTOP_PROC_MEM_RSS) + (1 << GLIBTOP_PROC_MEM_RSS_RLIM);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
||||
|
||||
if (pid == 0) {
|
||||
/* Client is only interested in the flags. */
|
||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||
return;
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_MEM, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_MEM): %s\n", strerror (errno));
|
||||
|
||||
buf->rss = tbl.proc_mem.rss;
|
||||
buf->rss_rlim = tbl.proc_mem.rlim;
|
||||
|
||||
if (table (TABLE_PROC_SEGMENT, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_SEGMENT): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||
|
||||
buf->vsize = tbl.proc_segment.vsize;
|
||||
buf->size = tbl.proc_segment.size;
|
||||
buf->resident = tbl.proc_segment.resident;
|
||||
buf->share = tbl.proc_segment.shared;
|
||||
}
|
68
sysdeps/kernel/procsegment.c
Normal file
68
sysdeps/kernel/procsegment.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procsegment.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment =
|
||||
(1 << GLIBTOP_PROC_SEGMENT_TRS) + (1 << GLIBTOP_PROC_SEGMENT_LRS) +
|
||||
(1 << GLIBTOP_PROC_SEGMENT_DRS) + (1 << GLIBTOP_PROC_SEGMENT_DT) +
|
||||
(1 << GLIBTOP_PROC_SEGMENT_START_CODE) + (1 << GLIBTOP_PROC_SEGMENT_END_CODE) +
|
||||
(1 << GLIBTOP_PROC_SEGMENT_START_STACK);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_segment));
|
||||
|
||||
if (pid == 0) {
|
||||
/* Client is only interested in the flags. */
|
||||
buf->flags = _glibtop_sysdeps_proc_segment;
|
||||
return;
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_MEM, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_MEM): %s\n", strerror (errno));
|
||||
|
||||
buf->start_code = tbl.proc_mem.start_code;
|
||||
buf->end_code = tbl.proc_mem.end_code;
|
||||
buf->start_stack = tbl.proc_mem.start_stack;
|
||||
|
||||
if (table (TABLE_PROC_SEGMENT, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_SEGMENT): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_segment;
|
||||
|
||||
buf->trs = tbl.proc_segment.trs;
|
||||
buf->lrs = tbl.proc_segment.lrs;
|
||||
buf->drs = tbl.proc_segment.drs;
|
||||
buf->dt = tbl.proc_segment.dt;
|
||||
}
|
59
sysdeps/kernel/procsignal.c
Normal file
59
sysdeps/kernel/procsignal.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procsignal.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
(1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) +
|
||||
(1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << GLIBTOP_PROC_SIGNAL_SIGCATCH);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_signal));
|
||||
|
||||
if (pid == 0) {
|
||||
/* Client is only interested in the flags. */
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
return;
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_SIGNAL, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_SIGNAL): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
|
||||
buf->signal = tbl.proc_signal.signal;
|
||||
buf->blocked = tbl.proc_signal.blocked;
|
||||
buf->sigignore = tbl.proc_signal.ignored;
|
||||
buf->sigcatch = tbl.proc_signal.caught;
|
||||
|
||||
}
|
65
sysdeps/kernel/procstate.c
Normal file
65
sysdeps/kernel/procstate.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procstate.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_state =
|
||||
(1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
#define NR_STATES 7
|
||||
|
||||
void
|
||||
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
static const char states [NR_STATES] = { 'R', 'S', 'D', 'Z', 'T', 'W', '.' };
|
||||
unsigned state;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_state));
|
||||
|
||||
if (pid == 0) {
|
||||
/* Client is only interested in the flags. */
|
||||
buf->flags = _glibtop_sysdeps_proc_state;
|
||||
return;
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_STATE, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_STATE): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_state;
|
||||
|
||||
memcpy (buf->cmd, tbl.proc_state.comm, sizeof (tbl.proc_state.comm));
|
||||
|
||||
state = (unsigned) tbl.proc_state.state;
|
||||
|
||||
if (state >= NR_STATES)
|
||||
state = NR_STATES;
|
||||
|
||||
buf->state = states [state];
|
||||
}
|
61
sysdeps/kernel/proctime.c
Normal file
61
sysdeps/kernel/proctime.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/proctime.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
(1 << GLIBTOP_PROC_TIME_UTIME) + (1 << GLIBTOP_PROC_TIME_CUTIME) +
|
||||
(1 << GLIBTOP_PROC_TIME_STIME) + (1 << GLIBTOP_PROC_TIME_CSTIME) +
|
||||
(1 << GLIBTOP_PROC_TIME_TIMEOUT) + (1 << GLIBTOP_PROC_TIME_IT_REAL_VALUE) +
|
||||
(1 << GLIBTOP_PROC_TIME_START_TIME);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||
|
||||
if (pid == 0) {
|
||||
/* Client is only interested in the flags. */
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
return;
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_TIME, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_TIME): %s\n", strerror (errno));
|
||||
|
||||
buf->utime = tbl.proc_time.utime;
|
||||
buf->stime = tbl.proc_time.stime;
|
||||
buf->cutime = tbl.proc_time.cutime;
|
||||
buf->cstime = tbl.proc_time.cstime;
|
||||
buf->timeout = tbl.proc_time.timeout;
|
||||
buf->it_real_value = tbl.proc_time.it_real_value;
|
||||
buf->start_time = tbl.proc_time.start_time;
|
||||
}
|
100
sysdeps/kernel/procuid.c
Normal file
100
sysdeps/kernel/procuid.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procuid.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
(1 << GLIBTOP_PROC_UID_UID) + (1 << GLIBTOP_PROC_UID_EUID) +
|
||||
(1 << GLIBTOP_PROC_UID_GID) + (1 << GLIBTOP_PROC_UID_EGID) +
|
||||
(1 << GLIBTOP_PROC_UID_PID) + (1 << GLIBTOP_PROC_UID_PPID) +
|
||||
(1 << GLIBTOP_PROC_UID_PGRP) + (1 << GLIBTOP_PROC_UID_SESSION) +
|
||||
(1 << GLIBTOP_PROC_UID_TTY) + (1 << GLIBTOP_PROC_UID_TPGID) +
|
||||
(1 << GLIBTOP_PROC_UID_PRIORITY) + (1 << GLIBTOP_PROC_UID_NICE);
|
||||
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
long def_priority, priority, nice;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_uid));
|
||||
|
||||
if (pid == 0) {
|
||||
/* Client is only interested in the flags. */
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
return;
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_UID, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_UID): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
|
||||
buf->uid = tbl.proc_uid.uid;
|
||||
buf->euid = tbl.proc_uid.euid;
|
||||
buf->gid = tbl.proc_uid.gid;
|
||||
buf->egid = tbl.proc_uid.egid;
|
||||
|
||||
buf->pid = tbl.proc_uid.pid;
|
||||
buf->ppid = tbl.proc_uid.ppid;
|
||||
buf->pgrp = tbl.proc_uid.pgrp;
|
||||
buf->session = tbl.proc_uid.session;
|
||||
buf->tty = tbl.proc_uid.tty;
|
||||
buf->tpgid = tbl.proc_uid.tpgid;
|
||||
|
||||
/* scale priority and nice values from timeslices to -20..20 */
|
||||
/* to make it look like a "normal" unix priority/nice value */
|
||||
|
||||
def_priority = tbl.proc_uid.def_priority;
|
||||
|
||||
priority = tbl.proc_uid.counter;
|
||||
priority = 20 - (priority * 10 + def_priority / 2) / def_priority;
|
||||
nice = tbl.proc_uid.priority;
|
||||
nice = 20 - (nice * 20 + def_priority / 2) / def_priority;
|
||||
|
||||
buf->priority = (int) priority;
|
||||
buf->nice = (int) nice;
|
||||
|
||||
if (buf->tty == 0)
|
||||
/* the old notty val, update elsewhere bef. moving to 0 */
|
||||
buf->tty = -1;
|
||||
|
||||
if (server->os_version_code < LINUX_VERSION(1,3,39)) {
|
||||
/* map old meanings to new */
|
||||
buf->priority = 2*15 - buf->priority;
|
||||
buf->nice = 15 - buf->nice;
|
||||
}
|
||||
if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
|
||||
/* when tty wasn't full devno */
|
||||
buf->tty = 4*0x100 + buf->tty;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
}
|
61
sysdeps/kernel/sem_limits.c
Normal file
61
sysdeps/kernel/sem_limits.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop/sem_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_sem_limits =
|
||||
(1 << GLIBTOP_IPC_SEMMAP) + (1 << GLIBTOP_IPC_SEMMNI) +
|
||||
(1 << GLIBTOP_IPC_SEMMNS) + (1 << GLIBTOP_IPC_SEMMNU) +
|
||||
(1 << GLIBTOP_IPC_SEMMSL) + (1 << GLIBTOP_IPC_SEMOPM) +
|
||||
(1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) +
|
||||
(1 << GLIBTOP_IPC_SEMVMX) + (1 << GLIBTOP_IPC_SEMAEM);
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
|
||||
{
|
||||
struct seminfo seminfo;
|
||||
union semun arg;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_sem_limits;
|
||||
|
||||
arg.array = (ushort *) &seminfo;
|
||||
semctl (0, 0, IPC_INFO, arg);
|
||||
|
||||
buf->semmap = seminfo.semmap;
|
||||
buf->semmni = seminfo.semmni;
|
||||
buf->semmns = seminfo.semmns;
|
||||
buf->semmnu = seminfo.semmnu;
|
||||
buf->semmsl = seminfo.semmsl;
|
||||
buf->semopm = seminfo.semopm;
|
||||
buf->semume = seminfo.semume;
|
||||
buf->semusz = seminfo.semusz;
|
||||
buf->semvmx = seminfo.semvmx;
|
||||
buf->semaem = seminfo.semaem;
|
||||
}
|
52
sysdeps/kernel/shm_limits.c
Normal file
52
sysdeps/kernel/shm_limits.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop/shm_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_shm_limits =
|
||||
(1 << GLIBTOP_IPC_SHMMAX) + (1 << GLIBTOP_IPC_SHMMIN) +
|
||||
(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) +
|
||||
(1 << GLIBTOP_IPC_SHMALL);
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
|
||||
{
|
||||
struct shminfo shminfo;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_shm_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_shm_limits;
|
||||
|
||||
shmctl (0, IPC_INFO, (struct shmid_ds *) &shminfo);
|
||||
|
||||
buf->shmmax = shminfo.shmmax;
|
||||
buf->shmmin = shminfo.shmmin;
|
||||
buf->shmmni = shminfo.shmmni;
|
||||
buf->shmseg = shminfo.shmseg;
|
||||
buf->shmall = shminfo.shmall;
|
||||
}
|
51
sysdeps/kernel/swap.c
Normal file
51
sysdeps/kernel/swap.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/swap.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static unsigned long _glibtop_sysdeps_swap =
|
||||
(1 << GLIBTOP_SWAP_TOTAL) + (1 << GLIBTOP_SWAP_USED) +
|
||||
(1 << GLIBTOP_SWAP_FREE);
|
||||
|
||||
/* Provides information about swap usage. */
|
||||
|
||||
void
|
||||
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_swap));
|
||||
|
||||
if (table (TABLE_SWAP, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_SWAP): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
buf->total = tbl.swap.total;
|
||||
buf->used = tbl.swap.used;
|
||||
buf->free = tbl.swap.free;
|
||||
}
|
54
sysdeps/kernel/uptime.c
Normal file
54
sysdeps/kernel/uptime.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/uptime.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
static unsigned long _glibtop_sysdeps_uptime =
|
||||
(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
|
||||
|
||||
/* Provides uptime and idle time. */
|
||||
|
||||
void
|
||||
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
if (table (TABLE_UPTIME, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_UPTIME): %s\n", strerror (errno));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
|
||||
#if 0
|
||||
fprintf (stderr, "Table (%u) = %lu, %lu\n",
|
||||
TABLE_UPTIME, tbl.uptime.uptime, tbl.uptime.idle);
|
||||
#endif
|
||||
|
||||
buf->uptime = (double) tbl.uptime.uptime / HZ;
|
||||
buf->idletime = (double) tbl.uptime.idle / HZ;
|
||||
}
|
Reference in New Issue
Block a user