1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1989-2011 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Eclipse Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.eclipse.org/org/documents/epl-v10.html * 11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12 * * 13 * Information and Software Systems Research * 14 * AT&T Research * 15 * Florham Park NJ * 16 * * 17 * Glenn Fowler <glenn.s.fowler@gmail.com> * 18 * * 19 ***********************************************************************/ 20 #pragma prototyped 21 /* 22 * Glenn Fowler 23 * AT&T Research 24 * 25 * process status stream interface definitions 26 */ 27 28 #ifndef _PSS_H 29 #define _PSS_H 1 30 31 #include <ast.h> 32 33 #define PSS_VERSION 20101201L 34 35 #define PSS_ALL (1<<0) /* match all */ 36 #define PSS_ATTACHED (1<<1) /* match attached */ 37 #define PSS_DETACHED (1<<2) /* match detached */ 38 #define PSS_LEADER (1<<3) /* match group leaders */ 39 #define PSS_NOLEADER (1<<4) /* no group leaders */ 40 #define PSS_PS (1<<5) /* force the ps method */ 41 #define PSS_TTY (1<<6) /* match disc.tty */ 42 #define PSS_UID (1<<7) /* match disc.uid */ 43 #define PSS_UNMATCHED (1<<8) /* return unmatched too */ 44 #define PSS_VERBOSE (1<<9) /* report all errors */ 45 46 #define PSS_ANCESTOR (1<<0) /* ancestor matched */ 47 #define PSS_CHILD (1<<1) /* on children chain */ 48 #define PSS_EXPLICIT (1<<2) /* explicit */ 49 #define PSS_MATCHED (1<<3) /* matched */ 50 #define PSS_PARENT (1<<4) /* on parent chain */ 51 52 #define PSS_FLAGS 0xff 53 #define PSS_NODEV ((Pss_dev_t)(-1)) 54 #define PSS_SCAN 0 55 #define PSS_ZOMBIE 'Z' 56 57 #define PSS_addr (1<<0) 58 #define PSS_args (1<<1) 59 #define PSS_command (1<<2) 60 #define PSS_cpu (1<<3) 61 #define PSS_flags (1<<4) 62 #define PSS_gid (1<<5) 63 #define PSS_job (1<<6) 64 #define PSS_nice (1<<7) 65 #define PSS_npid (1<<8) 66 #define PSS_pgrp (1<<9) 67 #define PSS_pid (1<<10) 68 #define PSS_ppid (1<<11) 69 #define PSS_pri (1<<12) 70 #define PSS_proc (1<<13) 71 #define PSS_refcount (1<<14) 72 #define PSS_rss (1L<<15) 73 #define PSS_sched (1L<<16) 74 #define PSS_sid (1L<<17) 75 #define PSS_size (1L<<18) 76 #define PSS_start (1L<<19) 77 #define PSS_state (1L<<20) 78 #define PSS_tgrp (1L<<21) 79 #define PSS_time (1L<<22) 80 #define PSS_tty (1L<<23) 81 #define PSS_uid (1L<<24) 82 #define PSS_wchan (1L<<25) 83 84 #define PSS_all (PSS_addr|PSS_args|PSS_command|PSS_cpu|PSS_flags|\ 85 PSS_gid|PSS_job|PSS_nice|PSS_npid|PSS_pgrp|PSS_pid|\ 86 PSS_ppid|PSS_pri|PSS_proc|PSS_refcount|PSS_rss|\ 87 PSS_sched|PSS_sid|PSS_size|PSS_start|PSS_state|\ 88 PSS_tgrp|PSS_time|PSS_tty|PSS_uid|PSS_wchan) 89 #define PSS_match (PSS_gid|PSS_pgrp|PSS_sid|PSS_tty|PSS_uid) 90 91 #undef hz /* who gets the prize for this? */ 92 93 typedef long Pss_dev_t; 94 typedef long Pss_id_t; 95 96 struct Pss_s; typedef struct Pss_s Pss_t; 97 98 typedef struct Pssent_s 99 { 100 int pss; 101 102 void* addr; 103 void* wchan; 104 105 char* args; 106 char* command; 107 char* sched; 108 char* ttyname; 109 110 Pss_dev_t tty; 111 112 size_t rss; 113 size_t size; 114 115 time_t start; 116 117 unsigned long time; 118 119 Pss_id_t job; 120 Pss_id_t npid; 121 Pss_id_t pid; 122 Pss_id_t pgrp; 123 Pss_id_t ppid; 124 Pss_id_t sid; 125 Pss_id_t tgrp; 126 127 Pss_id_t gid; 128 Pss_id_t uid; 129 130 long nice; 131 long pri; 132 133 int cpu; 134 int flags; 135 int proc; 136 int refcount; 137 int state; 138 } Pssent_t; 139 140 typedef struct Pssdata_s 141 { 142 struct Pssdata_s* next; 143 unsigned long data; 144 } Pssdata_t; 145 146 typedef struct Pssmatch_s 147 { 148 struct Pssmatch_s* next; 149 unsigned long field; 150 struct Pssdata_s* data; 151 } Pssmatch_t; 152 153 typedef struct Pssdisc_s 154 { 155 unsigned long version; /* interface version */ 156 unsigned long fields; /* PSS_[a-z]* field requests */ 157 unsigned long flags; /* PSS_[A-Z]* flags */ 158 char* command; /* caller command path */ 159 Pss_dev_t tty; /* PSS_TTY match value */ 160 Pss_id_t uid; /* PSS_UID match value */ 161 Pssmatch_t* match; /* match these fields */ 162 Error_f errorf; /* error function */ 163 } Pssdisc_t; 164 165 typedef struct Pssmeth_s 166 { 167 const char* name; /* method name */ 168 const char* usage; /* method usage */ 169 unsigned long fields; /* supported fields */ 170 int (*initf)(Pss_t*); 171 int (*readf)(Pss_t*, Pss_id_t); 172 int (*partf)(Pss_t*, Pssent_t*); 173 int (*fullf)(Pss_t*, Pssent_t*); 174 Pss_dev_t (*ttydevf)(Pss_t*, const char*); 175 char* (*ttynamef)(Pss_t*, Pssent_t*); 176 Pss_dev_t (*ttymapf)(Pss_t*, Pss_dev_t); 177 int (*donef)(Pss_t*); 178 } Pssmeth_t; 179 180 struct Pss_s 181 { 182 const char* id; /* library id string */ 183 Pssmeth_t* meth; /* method */ 184 185 #ifdef _PSS_PRIVATE_ 186 _PSS_PRIVATE_ 187 #endif 188 189 }; 190 191 #define pssinit(d,c,e) (memset(d,0,sizeof(*(d))),(d)->version=PSS_VERSION,(d)->command=(char*)(c),(d)->errorf=(Error_f)(e)) 192 193 extern Pss_t* pssopen(Pssdisc_t*); 194 extern Pssent_t* pssread(Pss_t*, Pss_id_t); 195 extern Pssent_t* psssave(Pss_t*, Pssent_t*); 196 extern int pssclose(Pss_t*); 197 198 extern int pssttyadd(Pss_t*, const char*, Pss_dev_t); 199 extern Pss_dev_t pssttydev(Pss_t*, const char*); 200 extern char* pssttyname(Pss_t*, Pssent_t*); 201 202 #endif 203