From bf919d11aedc8b4c52edbdfe02be9853d485f895 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Mon, 13 Mar 1995 19:34:44 +0000 Subject: Initial revision --- libps/filters.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 libps/filters.c (limited to 'libps/filters.c') diff --git a/libps/filters.c b/libps/filters.c new file mode 100644 index 00000000..0dff3dfa --- /dev/null +++ b/libps/filters.c @@ -0,0 +1,74 @@ +/* Some ps_filter_t's to restrict proc_stat_list's in various ways. + + Copyright (C) 1995 Free Software Foundation, Inc. + + Written by Miles Bader + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include +#include +#include +#include +#include + +#include "ps.h" +#include "common.h" + +/* ---------------------------------------------------------------- */ + +static bool +ps_own_p(proc_stat_t ps) +{ + static int own_uid = -1; + if (own_uid < 0) + own_uid = getuid(); + return own_uid == proc_stat_info(ps)->owner; +} +struct ps_filter ps_own_filter = +{"own", PSTAT_INFO, ps_own_p}; + +static bool +ps_not_sess_leader_p(proc_stat_t ps) +{ + return !(proc_stat_state(ps) & PSTAT_STATE_SESSLDR); +} +struct ps_filter ps_not_sess_leader_filter = +{"not-sess-leader", PSTAT_STATE, ps_not_sess_leader_p}; + +static bool +ps_unorphaned_p(proc_stat_t ps) +{ + int state = proc_stat_state(ps); + return !(state & PSTAT_STATE_ORPHANED) || (state & PSTAT_STATE_SESSLDR); +} +struct ps_filter ps_unorphaned_filter = +{"unorphaned", PSTAT_STATE, ps_unorphaned_p}; + +static bool +ps_ctty_p(proc_stat_t ps) +{ + return proc_stat_cttyid(ps) != MACH_PORT_NULL; +} +struct ps_filter ps_ctty_filter = +{"ctty", PSTAT_CTTYID, ps_ctty_p}; + +static bool +ps_parent_p(proc_stat_t ps) +{ + return !(proc_stat_state(ps) & PSTAT_STATE_NOPARENT); +} +struct ps_filter ps_parent_filter = +{"parent", PSTAT_STATE, ps_parent_p}; -- cgit v1.2.3