Blame sysdeps/osf1/procmem.c

Packit d37888
/* Copyright (C) 1998-99 Martin Baulig
Packit d37888
   This file is part of LibGTop 1.0.
Packit d37888
Packit d37888
   Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Packit d37888
Packit d37888
   LibGTop is free software; you can redistribute it and/or modify it
Packit d37888
   under the terms of the GNU General Public License as published by
Packit d37888
   the Free Software Foundation; either version 2 of the License,
Packit d37888
   or (at your option) any later version.
Packit d37888
Packit d37888
   LibGTop is distributed in the hope that it will be useful, but WITHOUT
Packit d37888
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit d37888
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit d37888
   for more details.
Packit d37888
Packit d37888
   You should have received a copy of the GNU General Public License
Packit d37888
   along with LibGTop; see the file COPYING. If not, write to the
Packit d37888
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit d37888
   Boston, MA 02110-1301, USA.
Packit d37888
*/
Packit d37888
Packit d37888
#include <config.h>
Packit d37888
#include <glibtop.h>
Packit d37888
#include <glibtop/error.h>
Packit d37888
#include <glibtop/procmem.h>
Packit d37888
Packit d37888
#include <glibtop_suid.h>
Packit d37888
Packit d37888
#include <sys/user.h>
Packit d37888
#include <sys/time.h>
Packit d37888
#include <sys/resource.h>
Packit d37888
Packit d37888
#include <mach.h>
Packit d37888
#include <mach/mach_types.h>
Packit d37888
#include <mach/task_info.h>
Packit d37888
Packit d37888
static const unsigned long _glibtop_sysdeps_proc_mem =
Packit d37888
(1L << GLIBTOP_PROC_MEM_VSIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) +
Packit d37888
(1L << GLIBTOP_PROC_MEM_RSS);
Packit d37888
Packit d37888
/* Init function. */
Packit d37888
Packit d37888
void
Packit d37888
_glibtop_init_proc_mem_p (glibtop *server)
Packit d37888
{
Packit d37888
	server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
Packit d37888
}
Packit d37888
Packit d37888
/* Provides detailed information about a process. */
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
Packit d37888
			pid_t pid)
Packit d37888
{
Packit d37888
	task_basic_info_data_t taskinfo;
Packit d37888
	int ret, info_count;
Packit d37888
	task_t thistask;
Packit d37888
	struct user u;
Packit d37888
Packit d37888
	glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_MEM, 0);
Packit d37888
Packit d37888
	memset (buf, 0, sizeof (glibtop_proc_mem));
Packit d37888
Packit d37888
	/* Get task structure. */
Packit d37888
Packit d37888
	ret = task_by_unix_pid (task_self(), pid, &thistask);
Packit d37888
Packit d37888
	if (ret != KERN_SUCCESS) return;
Packit d37888
Packit d37888
	/* Get taskinfo about this task. */
Packit d37888
Packit d37888
	info_count = TASK_BASIC_INFO_COUNT;
Packit d37888
Packit d37888
	ret = task_info (thistask, TASK_BASIC_INFO,
Packit d37888
			 (task_info_t) &taskinfo, &info_count);
Packit d37888
Packit d37888
	if (ret != KERN_SUCCESS) return;
Packit d37888
Packit d37888
	buf->resident = taskinfo.resident_size;
Packit d37888
	buf->rss = taskinfo.resident_size;
Packit d37888
	buf->vsize = taskinfo.virtual_size;
Packit d37888
Packit d37888
	/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
Packit d37888
Packit d37888
	glibtop_suid_enter (server);
Packit d37888
Packit d37888
	ret = table (TBL_UAREA, pid, (char *) &u, 1,
Packit d37888
		     sizeof (struct user));
Packit d37888
Packit d37888
	glibtop_suid_leave (server);
Packit d37888
Packit d37888
	/* !!! END OF SUID ROOT PART !!! */
Packit d37888
Packit d37888
	if (ret != 1) return;
Packit d37888
Packit d37888
	buf->rss_rlim = u.u_rlimit [RLIMIT_RSS].rlim_cur;
Packit d37888
Packit d37888
	buf->share = u.u_ru.ru_ixrss;
Packit d37888
Packit d37888
	buf->flags |= (1L << GLIBTOP_PROC_MEM_RSS_RLIM) |
Packit d37888
		(1L << GLIBTOP_PROC_MEM_SHARE);
Packit d37888
}