aboutsummaryrefslogtreecommitdiff
path: root/libps/ps.h
diff options
context:
space:
mode:
Diffstat (limited to 'libps/ps.h')
-rw-r--r--libps/ps.h345
1 files changed, 185 insertions, 160 deletions
diff --git a/libps/ps.h b/libps/ps.h
index 7ae8acb8..91fdc70b 100644
--- a/libps/ps.h
+++ b/libps/ps.h
@@ -1,8 +1,8 @@
/* Routines to gather and print process information.
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,99,2001,02 Free Software Foundation, Inc.
- Written by Miles Bader <miles@gnu.ai.mit.edu>
+ Written by Miles Bader <miles@gnu.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -40,8 +40,8 @@ struct ps_user
uid_t uid;
/* The status */
- enum ps_user_passwd_state passwd_state;
-
+ enum ps_user_passwd_state passwd_state;
+
/* The user's password file entry. Only valid if PASSWD_STATE ==
PS_USER_PASSWD_OK. */
struct passwd passwd;
@@ -85,7 +85,7 @@ enum ps_tty_name_state
struct ps_tty {
/* Which tty this refers to. */
file_t port;
-
+
/* The name of the tty, if we could figure it out. */
const char *name;
/* What state the name is in. */
@@ -125,17 +125,17 @@ struct ps_context
process_t server;
/* proc_stats for every process we know about, indexed by process id. */
- ihash_t procs;
+ struct hurd_ihash procs;
/* ps_ttys for every tty we know about, indexed by the terminal port. */
- ihash_t ttys;
+ struct hurd_ihash ttys;
/* ps_ttys for every tty we know about, indexed by their ctty id port
(from libc). */
- ihash_t ttys_by_cttyid;
+ struct hurd_ihash ttys_by_cttyid;
/* A ps_user for every user we know about, indexed by user-id. */
- ihash_t users;
+ struct hurd_ihash users;
/* Functions that can be set to extend the behavior of proc_stats. */
struct ps_user_hooks *user_hooks;
@@ -178,121 +178,134 @@ typedef unsigned ps_flags_t;
typedef unsigned ps_state_t;
struct proc_stat
- {
- /* Which process server this is from. */
- struct ps_context *context;
-
- /* The proc's process id; if <0 then this is a thread, not a process. */
- pid_t pid;
-
- /* Flags describing which fields in this structure are valid. */
- ps_flags_t flags;
- ps_flags_t failed; /* flags that we tried to set and couldn't. */
-
- /* Thread fields -- these are valid if PID < 0. */
- struct proc_stat *thread_origin; /* A proc_stat for the task we're in. */
- unsigned thread_index; /* Which thread in our proc we are. */
-
- /* A process_t port for the process. */
- process_t process;
-
- /* The mach task port for the process. */
- task_t task;
-
- /* A libc msgport for the process. This port is responded to by the
- process itself (usually by the c library); see <hurd/msg.defs> for the
- standard set of rpcs you can send to this port. Accordingly, you
- cannot depend on a timely (or any) reply to messages sent here --
- program carefully! */
- mach_port_t msgport;
-
- /* A pointer to the process's procinfo structure (as returned by
- proc_getinfo; see <hurd/hurd_types.h>). Vm_alloced. */
- struct procinfo *proc_info;
- /* The size of the info structure for deallocation purposes. */
- unsigned proc_info_size;
-
- /* If present, these are just pointers into the proc_info structure. */
- unsigned num_threads;
- task_basic_info_t task_basic_info;
-
- /* For a thread, the obvious structures; for a process, summaries of the
- proc's thread_{basic,sched}_info_t structures: sizes and cumulative
- times are summed, prioritys and delta time are averaged. The
- run_states are added by having running thread take precedence over
- waiting ones, and if there are any other incompatible states, simply
- using a bogus value of -1. Malloced. */
- thread_basic_info_t thread_basic_info;
- thread_sched_info_t thread_sched_info;
-
- /* For a blocked thread, these next fields describe how it's blocked. */
-
- /* A string (pointing into the thread_waits field of the parent
- procstat), describing what's being blocked on. If "KERNEL", a system
- call (not mach_msg), and thread_rpc is the system call number.
- Otherwise if thread_rpc isn't zero, this string describes the port the
- rpc is on; if thread_rpc is 0, this string describes a non-rpc event. */
- char *thread_wait;
- /* The rpc that it's blocked on. For a process the rpc blocking the
- first blocked thread (if any). 0 means no block. */
- mach_msg_id_t thread_rpc;
-
- /* Storage for child-thread waits. */
- char *thread_waits;
- size_t thread_waits_len;
-
- /* The task or thread suspend count (whatever this proc_stat refers to). */
- int suspend_count;
-
- /* A bitmask summarizing the scheduling state of this process and all its
- threads. See the PSTAT_STATE_ defines below for a list of bits. */
- ps_state_t state;
-
- /* A ps_user object for the owner of this process, or NULL if none. */
- struct ps_user *owner;
- int owner_uid; /* The corresponding UID, or -1. */
-
- /* The process's argv, as a string with each element separated by '\0'. */
- char *args;
- /* The length of ARGS. */
- unsigned args_len;
-
- /* Virtual memory statistics for the process, as returned by task_info;
- see <mach/task_info.h> for a description of task_events_info_t. */
- task_events_info_t task_events_info;
- task_events_info_data_t task_events_info_buf;
- unsigned task_events_info_size;
-
- /* Flags showing whether a field is vm_alloced or malloced. */
- unsigned proc_info_vm_alloced : 1;
- unsigned thread_waits_vm_alloced : 1;
- unsigned args_vm_alloced : 1;
-
- /* Various libc ports: */
-
- /* The process's ctty id port, or MACH_PORT_NULL if the process has no
- controlling terminal. Note that this is just a magic cookie; we use
- it to fetch a port to the actual terminal -- it's not useful for much
- else. */
- mach_port_t cttyid;
-
- /* A port to the process's current working directory. */
- mach_port_t cwdir;
-
- /* The process's auth port, which we can use to determine who the process
- is authenticated as. */
- mach_port_t auth;
-
- /* The process's umask, which controls which protection bits won't be set
- when creating a file. */
- unsigned umask;
-
- /* A ps_tty object for the process's controlling terminal. */
- struct ps_tty *tty;
-
- /* A hook for the user to use. */
- void *hook;
- };
+{
+ /* Which process server this is from. */
+ struct ps_context *context;
+
+ /* The proc's process id; if <0 then this is a thread, not a process. */
+ pid_t pid;
+
+ /* Flags describing which fields in this structure are valid. */
+ ps_flags_t flags;
+ ps_flags_t failed; /* flags that we tried to set and couldn't. */
+ ps_flags_t inapp; /* flags that don't apply to this procstat;
+ subset of FAILED. */
+
+ /* Thread fields -- these are valid if PID < 0. */
+ struct proc_stat *thread_origin; /* A proc_stat for the task we're in. */
+ unsigned thread_index; /* Which thread in our proc we are. */
+
+ /* A process_t port for the process. */
+ process_t process;
+
+ /* The mach task port for the process. */
+ task_t task;
+
+ /* A libc msgport for the process. This port is responded to by the
+ process itself (usually by the c library); see <hurd/msg.defs> for the
+ standard set of rpcs you can send to this port. Accordingly, you
+ cannot depend on a timely (or any) reply to messages sent here --
+ program carefully! */
+ mach_port_t msgport;
+
+ /* A pointer to the process's procinfo structure (as returned by
+ proc_getinfo; see <hurd/hurd_types.h>). Vm_alloced. */
+ struct procinfo *proc_info;
+ /* The size of the info structure for deallocation purposes. */
+ unsigned proc_info_size;
+
+ /* If present, these are just pointers into the proc_info structure. */
+ unsigned num_threads;
+ task_basic_info_t task_basic_info;
+
+ /* For a thread, the obvious structures; for a process, summaries of the
+ proc's thread_{basic,sched}_info_t structures: sizes and cumulative
+ times are summed, prioritys and delta time are averaged. The
+ run_states are added by having running thread take precedence over
+ waiting ones, and if there are any other incompatible states, simply
+ using a bogus value of -1. Malloced. */
+ thread_basic_info_t thread_basic_info;
+ thread_sched_info_t thread_sched_info;
+
+ /* For a blocked thread, these next fields describe how it's blocked. */
+
+ /* A string (pointing into the thread_waits field of the parent
+ procstat), describing what's being blocked on. If "KERNEL", a system
+ call (not mach_msg), and thread_rpc is the system call number.
+ Otherwise if thread_rpc isn't zero, this string describes the port the
+ rpc is on; if thread_rpc is 0, this string describes a non-rpc event. */
+ char *thread_wait;
+ /* The rpc that it's blocked on. For a process the rpc blocking the
+ first blocked thread (if any). 0 means no block. */
+ mach_msg_id_t thread_rpc;
+
+ /* Storage for child-thread waits. */
+ char *thread_waits;
+ size_t thread_waits_len;
+
+ /* The task or thread suspend count (whatever this proc_stat refers to). */
+ int suspend_count;
+
+ /* A bitmask summarizing the scheduling state of this process and all its
+ threads. See the PSTAT_STATE_ defines below for a list of bits. */
+ ps_state_t state;
+
+ /* A ps_user object for the owner of this process, or NULL if none. */
+ struct ps_user *owner;
+ int owner_uid; /* The corresponding UID, or -1. */
+
+ /* The process's argv, as a string with each element separated by '\0'. */
+ char *args;
+ /* The length of ARGS. */
+ size_t args_len;
+
+ /* Virtual memory statistics for the process, as returned by task_info;
+ see <mach/task_info.h> for a description of task_events_info_t. */
+ /* FIXME: we are actually currently storing it into proc_info, see
+ fetch_procinfo. */
+ task_events_info_t task_events_info;
+ task_events_info_data_t task_events_info_buf;
+ size_t task_events_info_size;
+
+ /* Flags showing whether a field is vm_alloced or malloced. */
+ unsigned proc_info_vm_alloced : 1;
+ unsigned thread_waits_vm_alloced : 1;
+ unsigned args_vm_alloced : 1;
+ unsigned env_vm_alloced : 1;
+
+ /* Various libc ports: */
+
+ /* The process's ctty id port, or MACH_PORT_NULL if the process has no
+ controlling terminal. Note that this is just a magic cookie; we use
+ it to fetch a port to the actual terminal -- it's not useful for much
+ else. */
+ mach_port_t cttyid;
+
+ /* A port to the process's current working directory. */
+ mach_port_t cwdir;
+
+ /* The process's auth port, which we can use to determine who the process
+ is authenticated as. */
+ mach_port_t auth;
+
+ /* The process's umask, which controls which protection bits won't be set
+ when creating a file. */
+ unsigned umask;
+
+ /* A ps_tty object for the process's controlling terminal. */
+ struct ps_tty *tty;
+
+ /* A hook for the user to use. */
+ void *hook;
+
+ /* XXX these members added at the end for binary compatibility */
+ /* The process's envp, as a string with each element separated by '\0'. */
+ char *env;
+ /* The length of ENV. */
+ size_t env_len;
+
+ unsigned num_ports;
+};
/* Proc_stat flag bits; each bit is set in the FLAGS field if that
information is currently valid. */
@@ -317,6 +330,7 @@ struct proc_stat
#define PSTAT_THREAD_WAIT 0x00800 /* The rpc the thread is waiting on. */
#define PSTAT_THREAD_WAITS 0x01000 /* Thread waits for this PS's threads */
#define PSTAT_ARGS 0x02000 /* The process's args */
+#define PSTAT_ENV 0x2000000 /* The process's environment */
#define PSTAT_STATE 0x04000 /* A bitmask describing the process's
state (see below) */
#define PSTAT_SUSPEND_COUNT 0x08000 /* Task/thread suspend count */
@@ -328,12 +342,13 @@ struct proc_stat
#define PSTAT_OWNER_UID 0x200000 /* The uid of the the proc's owner */
#define PSTAT_UMASK 0x400000 /* The proc's current umask */
#define PSTAT_HOOK 0x800000 /* Has a non-zero hook */
+#define PSTAT_NUM_PORTS 0x4000000 /* Number of Mach ports in the task */
/* Flag bits that don't correspond precisely to any field. */
#define PSTAT_NO_MSGPORT 0x1000000 /* Don't use the msgport at all */
/* Bits from PSTAT_USER_BASE on up are available for user-use. */
-#define PSTAT_USER_BASE 0x2000000
+#define PSTAT_USER_BASE 0x10000000
#define PSTAT_USER_MASK ~(PSTAT_USER_BASE - 1)
/* If the PSTAT_STATE flag is set, then the proc_stats state field holds a
@@ -390,7 +405,7 @@ struct proc_stat
/* This is a constant string holding a single character for each possible bit
in a proc_stats STATE field, in order from bit zero. These are intended
for printing a user-readable summary of a process's state. */
-char *proc_stat_state_tags;
+extern char *proc_stat_state_tags;
/* Process info accessor functions.
@@ -420,6 +435,8 @@ char *proc_stat_state_tags;
#define proc_stat_suspend_count(ps) ((ps)->suspend_count)
#define proc_stat_args(ps) ((ps)->args)
#define proc_stat_args_len(ps) ((ps)->args_len)
+#define proc_stat_env(ps) ((ps)->env)
+#define proc_stat_env_len(ps) ((ps)->env_len)
#define proc_stat_state(ps) ((ps)->state)
#define proc_stat_cttyid(ps) ((ps)->cttyid)
#define proc_stat_cwdir(ps) ((ps)->cwdir)
@@ -429,6 +446,7 @@ char *proc_stat_state_tags;
#define proc_stat_umask(ps) ((ps)->umask)
#define proc_stat_tty(ps) ((ps)->tty)
#define proc_stat_task_events_info(ps) ((ps)->task_events_info)
+#define proc_stat_num_ports(ps) ((ps)->num_ports)
#define proc_stat_has(ps, needs) (((ps)->flags & needs) == needs)
/* True if PS refers to a thread and not a process. */
@@ -442,7 +460,9 @@ error_t _proc_stat_create (pid_t pid, struct ps_context *context,
/* Frees PS and any memory/ports it references. Users shouldn't use this
routine; proc_stats are normally freed only when their ps_context goes
- away. */
+ away. Insubordinate users will make sure they free the thread proc_stats
+ before they free the corresponding process proc_stat since the thread_wait
+ fields of the former may reference the latter. */
void _proc_stat_free (struct proc_stat *ps);
/* Adds FLAGS to PS's flags, fetching information as necessary to validate
@@ -455,7 +475,7 @@ error_t proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags);
PS (N should be between 0 and the number of threads in the process). The
resulting proc_stat isn't fully functional -- most flags can't be set in
it. If N was out of range, EINVAL is returned. If a memory allocation
- error occured, ENOMEM is returned. Otherwise, 0 is returned. */
+ error occurred, ENOMEM is returned. Otherwise, 0 is returned. */
error_t proc_stat_thread_create (struct proc_stat *ps, unsigned n,
struct proc_stat **thread_ps);
@@ -504,7 +524,7 @@ struct ps_getter
ps_flags_t needs;
/* A function that will get the value; the protocol between this function
- and its caller is type-dependent. */
+ and its caller is type-dependent. */
void (*fn) ();
};
@@ -608,7 +628,7 @@ error_t ps_stream_write_int_field (struct ps_stream *stream,
int value, int width);
/* A PS_FMT_SPEC describes how to output something from a PROC_STAT; it
- is a combination of a getter (describing how to get the value), an output
+ is a combination of a getter (describing how to get the value), an output
function (which outputs the result of the getter), and a compare function
(which can be used to sort proc_stats according to how they are
output). It also specifies the default width of the field in which the
@@ -620,7 +640,7 @@ struct ps_fmt_spec
{
/* The name of the spec (and it's title, if TITLE is NULL). */
const char *name;
-
+
/* The title to be printed in the headers. */
const char *title;
@@ -673,7 +693,7 @@ struct ps_fmt_specs
struct ps_fmt_spec_block *expansions; /* Storage for expanded aliases. */
};
-/* An struct ps_fmt_specs, suitable for use with ps_fmt_specs_find,
+/* An struct ps_fmt_specs, suitable for use with ps_fmt_specs_find,
containing specs for most values in a proc_stat. */
extern struct ps_fmt_specs ps_std_fmt_specs;
@@ -730,24 +750,29 @@ struct ps_fmt_field
/* PS_FMT */
struct ps_fmt
- {
- /* A pointer to an array of struct ps_fmt_fields holding the individual
- fields to be formatted. */
- struct ps_fmt_field *fields;
- /* The (valid) length of the fields array. */
- unsigned num_fields;
-
- /* A set of proc_stat flags describing what a proc_stat needs to hold in
- order to print out every field in the fmt. */
- ps_flags_t needs;
-
- /* Storage for various strings pointed to by the fields. */
- char *src;
- size_t src_len; /* Size of SRC. */
-
- /* The string displayed by default for fields that have no valid value. */
- char *inval;
- };
+{
+ /* A pointer to an array of struct ps_fmt_fields holding the individual
+ fields to be formatted. */
+ struct ps_fmt_field *fields;
+ /* The (valid) length of the fields array. */
+ unsigned num_fields;
+
+ /* A set of proc_stat flags describing what a proc_stat needs to hold in
+ order to print out every field in the fmt. */
+ ps_flags_t needs;
+
+ /* Storage for various strings pointed to by the fields. */
+ char *src;
+ size_t src_len; /* Size of SRC. */
+
+ /* The string displayed by default for fields that aren't appropriate for
+ this procstat. */
+ char *inapp;
+
+ /* The string displayed by default for fields which are appropriate, but
+ couldn't be fetched due to some error. */
+ char *error;
+};
/* Accessor macros: */
#define ps_fmt_fields(fmt) ((fmt)->fields)
@@ -797,7 +822,7 @@ void ps_fmt_free (struct ps_fmt *fmt);
instance, you would like squash a format without destroying the original. */
error_t ps_fmt_clone (struct ps_fmt *fmt, struct ps_fmt **copy);
-/* Write an appropiate header line for FMT, containing the titles of all its
+/* Write an appropriate header line for FMT, containing the titles of all its
fields appropiately aligned with where the values would be printed, to
STREAM (without a trailing newline). If count is non-NULL, the total
number number of characters output is added to the integer it points to.
@@ -812,14 +837,14 @@ error_t ps_fmt_write_proc_stat (struct ps_fmt *fmt, struct proc_stat *ps,
struct ps_stream *stream);
/* Remove those fields from FMT for which the function FN, when called on the
- field, returns true. Appropiate inter-field characters are also removed:
+ field, returns true. Appropriate inter-field characters are also removed:
those *following* deleted fields at the beginning of the fmt, and those
- *preceeding* deleted fields *not* at the beginning. */
+ *preceding* deleted fields *not* at the beginning. */
void ps_fmt_squash (struct ps_fmt *fmt, int (*fn)(struct ps_fmt_field *field));
/* Remove those fields from FMT which would need the proc_stat flags FLAGS.
- Appropiate inter-field characters are also removed: those *following*
- deleted fields at the beginning of the fmt, and those *preceeding* deleted
+ Appropriate inter-field characters are also removed: those *following*
+ deleted fields at the beginning of the fmt, and those *preceding* deleted
fields *not* at the beginning. */
void ps_fmt_squash_flags (struct ps_fmt *fmt, ps_flags_t flags);
@@ -898,7 +923,7 @@ error_t proc_stat_list_merge (struct proc_stat_list *pp,
returned in them. */
error_t proc_stat_list_add_all (struct proc_stat_list *pp,
struct proc_stat ***proc_stats,
- unsigned *num_procs);
+ size_t *num_procs);
/* Add to PP entries for all processes in the login collection LOGIN_ID at
its context. If an error occurs, the system error code is returned,
@@ -907,7 +932,7 @@ error_t proc_stat_list_add_all (struct proc_stat_list *pp,
error_t proc_stat_list_add_login_coll (struct proc_stat_list *pp,
pid_t login_id,
struct proc_stat ***proc_stats,
- unsigned *num_procs);
+ size_t *num_procs);
/* Add to PP entries for all processes in the session SESSION_ID at its
context. If an error occurs, the system error code is returned, otherwise
@@ -916,7 +941,7 @@ error_t proc_stat_list_add_login_coll (struct proc_stat_list *pp,
error_t proc_stat_list_add_session (struct proc_stat_list *pp,
pid_t session_id,
struct proc_stat ***proc_stats,
- unsigned *num_procs);
+ size_t *num_procs);
/* Add to PP entries for all processes in the process group PGRP at its
context. If an error occurs, the system error code is returned, otherwise
@@ -924,7 +949,7 @@ error_t proc_stat_list_add_session (struct proc_stat_list *pp,
resulting entries is returned in them. */
error_t proc_stat_list_add_pgrp (struct proc_stat_list *pp, pid_t pgrp,
struct proc_stat ***proc_stats,
- unsigned *num_procs);
+ size_t *num_procs);
/* Try to set FLAGS in each proc_stat in PP (but they may still not be set
-- you have to check). If a fatal error occurs, the error code is
@@ -1009,7 +1034,7 @@ int proc_stat_list_spec_nominal (struct proc_stat_list *pp,
information on the data types these routines return. */
/* Return the current host port. */
-host_t ps_get_host ();
+mach_port_t ps_get_host ();
/* Return a pointer to basic info about the current host in HOST_INFO. Since
this is static global information we just use a static buffer. If a