summaryrefslogtreecommitdiff
path: root/sysdeps/sun4
diff options
context:
space:
mode:
authorMartin Baulig <baulig@Stud.Informatik.uni-trier.de>1998-07-17 16:40:02 +0000
committerMartin Baulig <martin@src.gnome.org>1998-07-17 16:40:02 +0000
commitc41d6e5a7774e1eaf94d94fa1d1c151a580a6104 (patch)
treebce598137ab12905ce120f9f67a39318b5c71c21 /sysdeps/sun4
parent74ca45f7950c6e1143f6050497dcee854f9d3550 (diff)
downloadlibgtop-c41d6e5a7774e1eaf94d94fa1d1c151a580a6104.tar.gz
Added implementation of that feature.
1998-07-17 Martin Baulig <baulig@Stud.Informatik.uni-trier.de> * sysdeps/sun4/proclist.c (glibtop_get_proclist_p): Added implementation of that feature. * sysdeps/sun4/proc_{uid,state}.c: Now working quite well. * sysdeps/sun4/proc_{mem,time,signal,kernel,segment}.c: Added some basic implementation; this isn't really working yet.
Diffstat (limited to 'sysdeps/sun4')
-rw-r--r--sysdeps/sun4/glibtop_machine.h8
-rw-r--r--sysdeps/sun4/open.c61
-rw-r--r--sysdeps/sun4/prockernel.c26
-rw-r--r--sysdeps/sun4/proclist.c57
-rw-r--r--sysdeps/sun4/procmem.c27
-rw-r--r--sysdeps/sun4/procsegment.c26
-rw-r--r--sysdeps/sun4/procsignal.c29
-rw-r--r--sysdeps/sun4/procstate.c26
-rw-r--r--sysdeps/sun4/proctime.c26
-rw-r--r--sysdeps/sun4/procuid.c37
-rw-r--r--sysdeps/sun4/uptime.c6
11 files changed, 310 insertions, 19 deletions
diff --git a/sysdeps/sun4/glibtop_machine.h b/sysdeps/sun4/glibtop_machine.h
index 55ec3cd6..662cf03c 100644
--- a/sysdeps/sun4/glibtop_machine.h
+++ b/sysdeps/sun4/glibtop_machine.h
@@ -85,6 +85,10 @@ struct _glibtop_machine
gid_t gid, egid; /* Real and effective group id */
int nlist_count; /* Number of symbols in the nlist */
int ncpu; /* Number of CPUs we have */
+ int nproc; /* Number of entries in the process array */
+ size_t ptable_size; /* Size of process array. */
+ unsigned long ptable_offset; /* Offset of process array in kernel. */
+ struct proc *proc_table; /* Process array. */
unsigned long pages, epages;
struct page *physpage;
int bytesize, count;
@@ -102,6 +106,10 @@ extern int _glibtop_check_nlist __P((void *, register struct nlist *));
extern int _glibtop_getkval __P((void *, unsigned long, int *, int, char *));
+extern void _glibtop_read_proc_table __P((void *));
+
+extern struct proc *_glibtop_find_pid __P((void *, pid_t));
+
#endif
__END_DECLS
diff --git a/sysdeps/sun4/open.c b/sysdeps/sun4/open.c
index 60f3c64b..f97fec38 100644
--- a/sysdeps/sun4/open.c
+++ b/sysdeps/sun4/open.c
@@ -118,6 +118,24 @@ glibtop_open_r (glibtop *server, const char *program_name,
(_glibtop_check_nlist (server, _glibtop_nlist) > 0))
_exit (1);
+ /* Get process array stuff. */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist[X_NPROC].n_value,
+ (int *)(&server->machine.nproc),
+ sizeof (server->machine.nproc),
+ _glibtop_nlist[X_NPROC].n_name);
+
+ (void) _glibtop_getkval (server, _glibtop_nlist[X_PROC].n_value,
+ (int *)(&server->machine.ptable_offset),
+ sizeof (server->machine.ptable_offset),
+ _glibtop_nlist[X_PROC].n_name);
+
+ server->machine.ptable_size = (unsigned long) server->machine.nproc *
+ (unsigned long) sizeof (struct proc);
+
+ server->machine.proc_table = glibtop_malloc_r
+ (server, server->machine.ptable_size);
+
/* This are for the memory statistics. */
(void) _glibtop_getkval (server, _glibtop_nlist[X_PAGES].n_value,
@@ -221,3 +239,46 @@ _glibtop_getkval (void *void_server, unsigned long offset, int *ptr, int size, c
return 1;
}
+
+/* Used internally. Reads process table from kernel. */
+
+void
+_glibtop_read_proc_table (void *void_server)
+{
+ glibtop *server = (glibtop *) void_server;
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* Read process table from kernel. */
+
+ (void) _glibtop_getkval (server, server->machine.ptable_offset,
+ (int *) server->machine.proc_table,
+ (size_t) server->machine.ptable_size,
+ _glibtop_nlist[X_PROC].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+}
+
+/* Used internally. Finds pid in process table. */
+
+struct proc *
+_glibtop_find_pid (void *void_server, pid_t pid)
+{
+ register struct proc *pp;
+ register int i;
+
+ glibtop *server = (glibtop *) void_server;
+
+ for (pp = server->machine.proc_table, i = 0;
+ i < server->machine.nproc; pp++, i++) {
+ if ((pp->p_stat != 0) && (pp->p_pid == pid))
+ return pp;
+ }
+
+ return NULL;
+}
diff --git a/sysdeps/sun4/prockernel.c b/sysdeps/sun4/prockernel.c
index f8596820..5f13b69f 100644
--- a/sysdeps/sun4/prockernel.c
+++ b/sysdeps/sun4/prockernel.c
@@ -19,16 +19,38 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
#include <glibtop/prockernel.h>
+static const unsigned long _glibtop_sysdeps_proc_kernel =
+(1 << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1 << GLIBTOP_PROC_KERNEL_WCHAN);
+
/* Provides detailed information about a process. */
void
glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
- pid_t pid)
+ pid_t pid)
{
+ struct proc *pp;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_kernel));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->k_flags = pp->p_flag;
+ buf->wchan = pp->p_wchan;
+
+ buf->flags = _glibtop_sysdeps_proc_kernel;
}
diff --git a/sysdeps/sun4/proclist.c b/sysdeps/sun4/proclist.c
index 0623dd23..bc8dfebc 100644
--- a/sysdeps/sun4/proclist.c
+++ b/sysdeps/sun4/proclist.c
@@ -19,10 +19,13 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/xmalloc.h>
#include <glibtop/proclist.h>
-#define GLIBTOP_PROCLIST_FLAGS 3
+static const unsigned long _glibtop_sysdeps_proclist =
+(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
+(1 << GLIBTOP_PROCLIST_SIZE);
/* Fetch list of currently running processes.
*
@@ -34,8 +37,56 @@
unsigned *
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
{
+ register struct proc *pp;
+ register int i, nproc = 0;
+ unsigned *proc_list = NULL;
+ size_t proc_size;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proclist));
- return NULL;
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Count number of processes. */
+
+ for (pp = server->machine.proc_table, i = 0;
+ i < server->machine.nproc; pp++, i++) {
+ if (pp->p_stat == 0)
+ continue;
+ else
+ nproc++;
+ }
+
+ if (nproc == 0) /* Should never happen. */
+ return NULL;
+
+ /* Allocate space for process list. */
+
+ proc_size = nproc * sizeof (unsigned);
+
+ proc_list = glibtop_malloc_r (server, proc_size);
+
+ /* Write process list. */
+
+ for (pp = server->machine.proc_table, i = 0, nproc = 0;
+ i < server->machine.nproc; pp++, i++) {
+ if (pp->p_stat == 0)
+ continue;
+ proc_list [nproc++] = pp->p_pid;
+ }
+
+ /* Since everything is ok now, we can set buf->flags, fill in the remaining fields
+ and return proc_list. */
+
+ buf->flags = _glibtop_sysdeps_proclist;
+
+ buf->size = sizeof (unsigned);
+ buf->number = nproc;
+
+ buf->total = nproc * sizeof (unsigned);
+
+ return proc_list;
}
diff --git a/sysdeps/sun4/procmem.c b/sysdeps/sun4/procmem.c
index c6971c8b..256fa98c 100644
--- a/sysdeps/sun4/procmem.c
+++ b/sysdeps/sun4/procmem.c
@@ -22,13 +22,38 @@
#include <config.h>
#include <glibtop/procmem.h>
+static const unsigned long _glibtop_sysdeps_proc_mem =
+(1 << GLIBTOP_PROC_MEM_SIZE) + (1 << GLIBTOP_PROC_MEM_RSS) +
+(1 << GLIBTOP_PROC_MEM_RSS_RLIM);
+
/* Provides detailed information about a process. */
void
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
- pid_t pid)
+ pid_t pid)
{
+ struct proc *pp;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_mem));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->size = (pp)->p_tsize + (pp)->p_dsize + (pp)->p_ssize;
+
+ buf->rss = pp->p_rssize;
+ buf->rss_rlim = pp->p_maxrss;
+
+ buf->flags = _glibtop_sysdeps_proc_mem;
}
diff --git a/sysdeps/sun4/procsegment.c b/sysdeps/sun4/procsegment.c
index d0d957c3..8df0f083 100644
--- a/sysdeps/sun4/procsegment.c
+++ b/sysdeps/sun4/procsegment.c
@@ -19,16 +19,38 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
#include <glibtop/procsegment.h>
+static const unsigned long _glibtop_sysdeps_proc_segment =
+(1 << GLIBTOP_PROC_SEGMENT_TRS) + (1 << GLIBTOP_PROC_SEGMENT_DRS);
+
/* Provides detailed information about a process. */
void
glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
- pid_t pid)
+ pid_t pid)
{
+ struct proc *pp;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_segment));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->trs = pp->p_tsize;
+ buf->drs = pp->p_dsize;
+
+ buf->flags = _glibtop_sysdeps_proc_segment;
}
diff --git a/sysdeps/sun4/procsignal.c b/sysdeps/sun4/procsignal.c
index bee1dc5f..ff256200 100644
--- a/sysdeps/sun4/procsignal.c
+++ b/sysdeps/sun4/procsignal.c
@@ -19,16 +19,41 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
#include <glibtop/procsignal.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_p (glibtop *server, glibtop_proc_signal *buf,
- pid_t pid)
+ pid_t pid)
{
+ struct proc *pp;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_signal));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->signal = pp->p_sig;
+ buf->blocked = pp->p_sigmask;
+ buf->sigignore = pp->p_sigignore;
+ buf->sigcatch = pp->p_sigcatch;
+
+ buf->flags = _glibtop_sysdeps_proc_signal;
}
diff --git a/sysdeps/sun4/procstate.c b/sysdeps/sun4/procstate.c
index ddc6d92c..d3066a9c 100644
--- a/sysdeps/sun4/procstate.c
+++ b/sysdeps/sun4/procstate.c
@@ -19,16 +19,38 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
#include <glibtop/procstate.h>
+static const unsigned long _glibtop_sysdeps_proc_state =
+(1 << GLIBTOP_PROC_STATE_STATE) + (1 << GLIBTOP_PROC_STATE_UID);
+
/* Provides detailed information about a process. */
void
glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
- pid_t pid)
+ pid_t pid)
{
+ struct proc *pp;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_state));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->state = pp->p_stat;
+ buf->uid = pp->p_uid;
+
+ buf->flags = _glibtop_sysdeps_proc_state;
}
diff --git a/sysdeps/sun4/proctime.c b/sysdeps/sun4/proctime.c
index 32b237db..89673e11 100644
--- a/sysdeps/sun4/proctime.c
+++ b/sysdeps/sun4/proctime.c
@@ -19,16 +19,38 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
#include <glibtop/proctime.h>
+static const unsigned long _glibtop_sysdeps_proc_time =
+(1 << GLIBTOP_PROC_TIME_START_TIME) + (1 << GLIBTOP_PROC_TIME_UTIME);
+
/* Provides detailed information about a process. */
void
glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
- pid_t pid)
+ pid_t pid)
{
+ struct proc *pp;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_time));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->start_time = pp->p_time;
+ buf->utime = pp->p_cpticks;
+
+ buf->flags = _glibtop_sysdeps_proc_time;
}
diff --git a/sysdeps/sun4/procuid.c b/sysdeps/sun4/procuid.c
index bf132521..f30142b1 100644
--- a/sysdeps/sun4/procuid.c
+++ b/sysdeps/sun4/procuid.c
@@ -19,16 +19,49 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
#include <glibtop/procuid.h>
+static const unsigned long _glibtop_sysdeps_proc_uid =
+(1 << GLIBTOP_PROC_UID_UID) + (1 << GLIBTOP_PROC_UID_EUID) +
+(1 << GLIBTOP_PROC_UID_EGID) + (1 << GLIBTOP_PROC_UID_PID) +
+(1 << GLIBTOP_PROC_UID_PPID) + (1 << GLIBTOP_PROC_UID_PGRP) +
+(1 << GLIBTOP_PROC_UID_TPGID) + (1 << GLIBTOP_PROC_UID_PRIORITY) +
+(1 << GLIBTOP_PROC_UID_NICE);
+
/* Provides detailed information about a process. */
void
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
- pid_t pid)
+ pid_t pid)
{
+ struct proc *pp;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_proc_uid));
+
+ /* Read process table from kernel. */
+
+ _glibtop_read_proc_table (server);
+
+ /* Find the pid in the process table. */
+
+ pp = _glibtop_find_pid (server, pid);
+
+ if (pp == NULL) return;
+
+ /* Fill in data fields. */
+
+ buf->uid = pp->p_uid;
+ buf->euid = pp->p_suid;
+ buf->egid = pp->p_sgid;
+ buf->pid = pp->p_pid;
+ buf->ppid = pp->p_ppid;
+ buf->pgrp = pp->p_pgrp;
+ buf->tpgid = pp->p_pgrp;
+ buf->priority = pp->p_pri;
+ buf->nice = pp->p_nice;
+
+ buf->flags = _glibtop_sysdeps_proc_uid;
}
diff --git a/sysdeps/sun4/uptime.c b/sysdeps/sun4/uptime.c
index db0d4a52..0a3827fb 100644
--- a/sysdeps/sun4/uptime.c
+++ b/sysdeps/sun4/uptime.c
@@ -41,9 +41,9 @@ glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
/* Make sure all required fields are present. */
- if (((cpu.flags & GLIBTOP_CPU_TOTAL) == 0) ||
- ((cpu.flags & GLIBTOP_CPU_IDLE) == 0) ||
- ((cpu.flags & GLIBTOP_CPU_FREQUENCY) == 0) ||
+ if (((cpu.flags & (1 << GLIBTOP_CPU_TOTAL)) == 0) ||
+ ((cpu.flags & (1 << GLIBTOP_CPU_IDLE)) == 0) ||
+ ((cpu.flags & (1 << GLIBTOP_CPU_FREQUENCY)) == 0) ||
(cpu.frequency == 0))
return;