diff options
Diffstat (limited to 'libps')
-rw-r--r-- | libps/procstat.c | 17 | ||||
-rw-r--r-- | libps/ps.h | 11 | ||||
-rw-r--r-- | libps/spec.c | 10 |
3 files changed, 37 insertions, 1 deletions
diff --git a/libps/procstat.c b/libps/procstat.c index f6420eea..d0423410 100644 --- a/libps/procstat.c +++ b/libps/procstat.c @@ -956,6 +956,23 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags) } } + /* The process's path to binary executable */ + if (NEED (PSTAT_EXE, PSTAT_PID)) + { + ps->exe = malloc (sizeof(string_t)); + if (ps->exe) + { + if (proc_get_exe (server, ps->pid, ps->exe)) + free (ps->exe); + else + { + ps->exe_len = strlen(ps->exe); + have |= PSTAT_EXE; + ps->exe_vm_alloced = 0; + } + } + } + /* The ctty id port; 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. */ @@ -272,6 +272,7 @@ struct proc_stat unsigned thread_waits_vm_alloced : 1; unsigned args_vm_alloced : 1; unsigned env_vm_alloced : 1; + unsigned exe_vm_alloced : 1; /* Various libc ports: */ @@ -305,6 +306,11 @@ struct proc_stat size_t env_len; unsigned num_ports; + + /* The path to process's binary executable. */ + char *exe; + /* The length of EXE. */ + size_t exe_len; }; /* Proc_stat flag bits; each bit is set in the FLAGS field if that @@ -344,12 +350,13 @@ struct proc_stat #define PSTAT_HOOK 0x800000 /* Has a non-zero hook */ #define PSTAT_NUM_PORTS 0x4000000 /* Number of Mach ports in the task */ #define PSTAT_TIMES 0x8000000 /* Task/thread user and system times */ +#define PSTAT_EXE 0x10000000 /* Path to binary executable */ /* 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 0x10000000 +#define PSTAT_USER_BASE 0x20000000 #define PSTAT_USER_MASK ~(PSTAT_USER_BASE - 1) /* If the PSTAT_STATE flag is set, then the proc_stats state field holds a @@ -448,6 +455,8 @@ extern char *proc_stat_state_tags; #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_exe(ps) ((ps)->exe) +#define proc_stat_exe_len(ps) ((ps)->exe_len) #define proc_stat_has(ps, needs) (((ps)->flags & needs) == needs) /* True if PS refers to a thread and not a process. */ diff --git a/libps/spec.c b/libps/spec.c index 5e540f87..4760c431 100644 --- a/libps/spec.c +++ b/libps/spec.c @@ -358,6 +358,14 @@ ps_get_num_ports (struct proc_stat *ps) const struct ps_getter ps_num_ports_getter = {"num_ports", PSTAT_NUM_PORTS, (vf) ps_get_num_ports}; +static void +ps_get_exe (struct proc_stat *ps, char **exe_p, int *exe_len_p) +{ + *exe_p = proc_stat_exe (ps); + *exe_len_p = proc_stat_exe_len (ps); +} +const struct ps_getter ps_exe_getter = +{"exe", PSTAT_EXE, ps_get_exe}; /* ---------------------------------------------------------------- */ /* some printing functions */ @@ -1166,6 +1174,8 @@ static const struct ps_fmt_spec specs[] = &ps_zero_fills_getter, ps_emit_int, ps_cmp_ints, ps_nominal_zint}, {"Ports", 0, -5, -1, 0, &ps_num_ports_getter, ps_emit_int, ps_cmp_ints, 0}, + {"Exe", 0, 0, -1, 0, + &ps_exe_getter, ps_emit_string, ps_cmp_strings,ps_nominal_string}, {0} }; |