home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 8.ddi / usr / include / sys / proc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  11.9 KB  |  362 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ifndef _SYS_PROC_H
  11. #define _SYS_PROC_H
  12.  
  13. #ident    "@(#)/usr/include/sys/proc.h.sl 1.1 4.0 12/08/90 46845 AT&T-USL"
  14.  
  15. #include <sys/immu.h>
  16. #include <sys/param.h>
  17.  
  18. /*
  19.  * One structure allocated per active process.  It contains all
  20.  * data needed about the process while the process may be swapped
  21.  * out.  Other per-process data (user.h) may be swapped with the
  22.  * process.
  23.  */
  24.  
  25. typedef struct    proc {
  26.     char    p_stat;            /* status of process */
  27.     char    p_cpu;            /* cpu usage for scheduling */
  28.     u_char    p_curflt;        /* current fault (/proc) */
  29.     u_char    p_swlocks;        /* number of swap vnode locks held */
  30.     u_int    p_flag;            /* flags defined below */
  31.     o_uid_t    p_uid;            /* real user id */
  32.  
  33.     /* the following pid fields declared o_pid_t are for
  34.     ** binary compatibility only. They will be removed in
  35.     ** the next release following SVR4.0.
  36.     */
  37.  
  38.     o_pid_t    p_oppid;        /* process id of parent*/
  39.     o_pid_t    p_opgrp;        /* name of process group leader */
  40.     o_pid_t    p_opid;            /* unique process id*/
  41.     struct    cred    *p_cred;    /* process credentials */
  42.     struct sess    *p_sessp;    /* session information */
  43.     int    p_pri;            /* scheduling priority */
  44.     
  45.     union {                /* wait addr for sleeping processes */
  46.         caddr_t p_cad;        /* Union is for XENIX compatibility */
  47.         int    p_int;
  48.     } p_unw;
  49. #define p_wchan p_unw.p_cad        /* Map MP name to old UNIX name */
  50. #define p_arg    p_unw.p_int        /* Map MP name to old UNIX name */
  51.  
  52.     struct    proc    *p_link;    /* forward link */
  53.     struct    proc    *p_parent;    /* ptr to parent process */
  54.     struct    proc    *p_child;    /* ptr to first child process */
  55.     struct    proc    *p_sibling;    /* ptr to next sibling proc on chain */
  56.     int    p_clktim;        /* time to alarm clock signal */
  57.  
  58.     caddr_t    p_brkbase;        /* base address of heap */
  59.     u_int    p_brksize;        /* heap size in bytes */
  60.     caddr_t    p_stkbase;        /* base address of stack */
  61.     u_int    p_stksize;        /* stack size in bytes */
  62.  
  63.     u_int    p_swrss;        /* resident set size before last swap */
  64.     clock_t    p_utime;        /* user time, this process */
  65.     clock_t    p_stime;        /* system time, this process */
  66.                      
  67.     ushort    p_usize;        /* size of u-block (*4096 bytes) */
  68.     ushort    p_user_license;        /* per-user licensing */
  69.  
  70.     caddr_t    p_ldt;            /* address of ldt */
  71.  
  72.     /* for MERGE386    */
  73.     struct    vm86    *p_vm86p;    /* info about Merge vm86 task */
  74.  
  75.     struct as *p_as;        /* process address space pointer */
  76.     int     p_wdata;        /* current wait return value */
  77.     char    p_wcode;        /* current wait code */
  78.     char    p_pollflag;        /* flags for use during poll(2) */
  79.     u_char    p_cursig;        /* current signal */
  80.     pid_t    p_epid;            /* effective pid; normally same as
  81.                      * p_pid; for servers, the system that
  82.                      * sent the msg
  83.                      */
  84.     sysid_t p_sysid;        /* normally same as sysid; for servers,
  85.                      * the system that sent the msg
  86.                      */
  87.     struct    proc  *p_rlink;        /* linked list for server */
  88.     int    p_srwchan;        /* RFS server awaiting work; sleep */
  89.     struct    vnode *p_trace;        /* pointer to /proc vnode */
  90.     k_sigset_t p_sig;        /* signals pending to this process */
  91.     k_sigset_t p_sigmask;        /* tracing signal mask for /proc */
  92.     k_sigset_t p_hold;        /* hold signal bit mask */
  93.     k_sigset_t p_ignore;        /* ignore when generated */
  94.     k_sigset_t p_siginfo;        /* gets signal info with signal */
  95.     struct    v86dat *p_v86;        /* pointer to v86 structure */
  96.  
  97.     ushort    p_raiocnt;        /* # of outstanding raw disk AIOs */
  98.  
  99.     char    p_filler1[70];        /* unused */
  100.  
  101.     u_short    p_whystop;
  102.     u_short    p_whatstop;
  103.  
  104.     pte_t    *p_ubptbl;        /* pointer to (floating) ublock page tbl */
  105.  
  106.     char    p_filler2[68];        /* unused */
  107.  
  108.     k_fltset_t    p_fltmask;    /* mask of traced faults (/proc) */
  109.     struct    evpd    *p_evpdp;    /* ptr to events per-process data */
  110.  
  111.     struct timer  *p_italarm[2];    /* Ptrs to the alarms for the clocks
  112.                      * measuring user  process virtual
  113.                      * time and user+system process
  114.                      * virtual time.
  115.                      */
  116.     struct proc *p_pglink;        /* process group hash chain link */
  117.     clock_t    p_cutime;        /* sum of children's user time */
  118.     clock_t    p_cstime;        /* sum of children's system time */
  119.      short    p_aiocount;        /* # of async requests accepted */
  120.      short    p_aiowcnt;        /* # of async operations currently
  121.                       * in progress and the process is
  122.                       * waiting for their completion
  123.                      */
  124.      id_t    p_cid;            /* scheduling class id */
  125.      _VOID    *p_clproc;        /* per process class specific data */
  126.      struct classfuncs *p_clfuncs;    /* ptr to structure containing
  127.                       * class specific function ptrs
  128.                      */
  129.     struct sigqueue *p_sigqueue;    /* queued siginfo structures */
  130.     struct sigqueue *p_curinfo;    /* siginfo for current signal */
  131.     caddr_t *p_segacct;        /* segment accounting info */
  132.     struct seguser *p_segu;        /* u segment */
  133.     struct    vnode *p_exec;        /* pointer to a.out vnode */
  134.     pid_t   p_ppid;         /* process id of parent*/
  135.     struct pid *p_pidp;     /* process ID info */
  136.     struct pid *p_pgidp;        /* process group ID info */
  137.     struct sd *p_sdp;       /* pointer to XENIX shared data */
  138.     struct proc *p_next;        /* active chain link */
  139.     struct proc *p_nextofkin;   /* gets accounting info at exit */
  140.     struct proc *p_orphan;
  141.     struct proc *p_nextorph;
  142. } proc_t;
  143.  
  144. extern proc_t *practive;
  145.  
  146. /* Well known processes */
  147.  
  148. extern proc_t *proc_sched;      /* memory scheduler */
  149. extern proc_t *proc_init;       /* init */
  150. extern proc_t *proc_pageout;        /* pageout daemon */
  151. extern proc_t *proc_bdflush;        /* block cache flush daemon */
  152.  
  153. /* process ID info */
  154.  
  155. struct pid {
  156.     unsigned int pid_prinactive :1;
  157.     unsigned int pid_pgorphaned :1;
  158.     unsigned int pid_ref :6;
  159.     unsigned int pid_prslot :24;
  160.     pid_t pid_id;
  161.     struct proc *pid_pglink;
  162.     struct pid *pid_link;
  163. };
  164.  
  165. extern struct pid pid0;
  166.  
  167. #define p_pgrp p_pgidp->pid_id
  168. #define p_pid  p_pidp->pid_id
  169. #define p_slot p_pidp->pid_prslot
  170. #define p_detached p_pgidp->pid_pgorphaned
  171.  
  172. #define PID_HOLD(pidp)  (++(pidp)->pid_ref)
  173. #define PID_RELE(pidp)    ((pidp)->pid_ref>1 ? --(pidp)->pid_ref : pid_rele(pidp))
  174.  
  175.  
  176. #if defined(_KERNEL)
  177.  
  178. #if defined(__STDC__)
  179.  
  180. /* process management functions */
  181. extern caddr_t findvaddr(proc_t *);
  182. extern paddr_t vtop(caddr_t, proc_t *);
  183. extern void pexit(void);
  184. extern int newproc(int, pid_t *, int *);
  185. extern void vfwait(pid_t);
  186. extern void freeproc(proc_t *);
  187. extern void setrun(proc_t *);
  188. extern void unsleep(proc_t *);
  189. extern void exit(int, int);
  190. extern void relvm(proc_t *);
  191.  
  192. extern void sigcld(proc_t *);
  193. extern void psig(void);
  194. extern int stop(proc_t *, int, int, int);
  195. extern int issig(int);
  196. extern void psignal(proc_t *, int);
  197. extern void sigtoproc(proc_t *, int, int);
  198.  
  199. void pid_setmin(void);
  200. pid_t pid_assign(int, proc_t **);
  201. int pid_rele(struct pid *);
  202. void pid_exit(proc_t *);
  203. proc_t *prfind(pid_t);
  204. proc_t *pgfind(pid_t);
  205. void pid_init(void);
  206. proc_t *pid_entry(int);
  207. int pid_slot(proc_t *);
  208. void signal(pid_t, int);
  209. void prsignal(struct pid *, int);
  210.  
  211. void pgsignal(struct pid *, int);
  212. void pgjoin(proc_t *, struct pid *);
  213. void pgexit(proc_t *);
  214. void pgdetach(proc_t *);
  215. int pgmembers(pid_t);
  216.  
  217.  
  218. #else 
  219.  
  220. extern caddr_t findvaddr();
  221. extern paddr_t vtop();
  222. extern void pexit();
  223. extern int newproc();
  224. extern void vfwait();
  225. extern void freeproc();
  226. extern void setrun();
  227. extern void unsleep();
  228. extern void exit();
  229. extern void relvm();
  230.  
  231. extern void sigcld();
  232. extern void psig();
  233. extern int stop();
  234. extern int issig();
  235. extern void psignal();
  236. extern void sigtoproc();
  237.  
  238. void pid_setmin();
  239. pid_t pid_assign();
  240. int pid_rele();
  241. void pid_exit();
  242. proc_t *prfind();
  243. proc_t *pgfind();
  244. void pid_init();
  245. proc_t *pid_entry();
  246. int pid_slot();
  247. void signal();
  248. void prsignal();
  249.  
  250. void pgsignal();
  251. void pgjoin();
  252. void pgexit();
  253. void pgdetach();
  254. int pgmembers();
  255.  
  256. #endif /* __STDC__ */
  257.  
  258. #endif /* _KERNEL */
  259.  
  260. /* stat codes */
  261.  
  262. #define    SSLEEP    1        /* awaiting an event */
  263. #define    SRUN    2        /* running */
  264. #define    SZOMB    3        /* process terminated but not waited for */
  265. #define    SSTOP    4        /* process stopped by debugger */
  266. #define    SIDL    5        /* intermediate state in process creation */
  267. #define    SONPROC    6        /* process is being run on a processor */
  268. #define SXBRK    7        /* process being xswapped */
  269.  
  270. /* flag codes */
  271.  
  272. #define    SSYS    0x00000001    /* system (resident) process */
  273. #define    STRC    0x00000002    /* process is being traced */
  274. #define    SPRWAKE    0x00000004    /* debugger is waiting to prlock() */
  275. #define    SNWAKE    0x00000008    /* process cannot be awakened by a signal */
  276. #define    SLOAD    0x00000010    /* in core */
  277. #define    SLOCK   0x00000020    /* process cannot be swapped */
  278. #define SLKDONE 0x00000040    /* NFS record-locking has been done */
  279. #define    SPOLL    0x00000080    /* process in stream poll */
  280. #define    SPRSTOP    0x00000100    /* process is being stopped via /proc */
  281. #define    SPROCTR    0x00000200    /* signal or syscall tracing via /proc */
  282. #define    SPROCIO    0x00000400    /* doing I/O via /proc, so don't run */
  283. #define    SPRFORK    0x00000800    /* child inherits /proc tracing flags */
  284. #define    SPROPEN    0x00001000    /* process is open via /proc */
  285. #define    SULOAD  0x00002000    /* u-block in core */
  286. #define    SRUNLCL    0x00004000    /* set process running on last /proc close */
  287. #define    SNOSTOP    0x00008000    /* proc asleep, stop not allowed */
  288. #define    SPTRX    0x00010000    /* process is exiting via ptrace(2) */
  289. #define    SASLEEP    0x00020000    /* proc is stopped within a call to sleep() */
  290. #define    SUSWAP    0x00040000    /* u-block is being swapped in or out */
  291. #define    SUWANT    0x00080000    /* waiting for u-block swap to complete */
  292. #define SEXECED 0x00100000    /* this process has execed */
  293. #define SDETACHED 0x00200000    /* this process detached from ctty */
  294. /* unused     0x00400000 */
  295. /* unused    0x00800000 */
  296. #define SJCTL    0x01000000    /* SIGCLD sent when children stop/continue */
  297. #define SNOWAIT 0x02000000    /* children never become zombies */
  298. #define SVFORK    0x04000000    /* process resulted from vfork */
  299. #define SVFDONE 0x08000000    /* vfork child releasing parent as */
  300. #define SSWLOCKS 0x10000000    /* process has swap locks */
  301. #define    SXSTART    0x20000000    /* setrun() by SIGCONT or ptrace() */
  302. #define    SPSTART    0x40000000    /* setrun() by /proc */
  303. #define    SNEWSYS    0x80000000    /* proc in sys class being created */
  304.  
  305. /* pollflags */
  306.  
  307. #define SINPOLL        0x01    /* process in poll */
  308. #define SPOLLTIME    0x02    /* poll timeout pending */
  309.  
  310. /* Flags for p_user_license */
  311.  
  312. #define PU_LIM_OK    0x01
  313. #define PU_LOGIN_PROC    0x02
  314. #define PU_UUCP        0x04
  315.  
  316. #define EUA_GET_LIM    0
  317. #define EUA_GET_CUR    1
  318. #define EUA_REM_USER    3
  319. #define EUA_ADD_USER    4
  320. #define EUA_UUCP    5
  321. #define EUA_FORK    6
  322.  
  323. /* Flags for newproc() */
  324.  
  325. #define NP_FAILOK    0x01    /* don't panic if cannot create process */
  326. #define NP_NOLAST    0x02    /* don't use last process slot */
  327. #define    NP_SYSPROC    0x04    /* system (resident) process */
  328. #define    NP_INIT        0x08    /* this is init process */
  329. #define NP_VFORK    0x10    /* share address space - vfork */
  330. #define NP_SHARE    0x20    /* share address space - asyncio */
  331.  
  332. /* Macro to convert proc table pointers to user block pointers */
  333. #define PTOU(p) ((struct user *)((p)->p_segu))
  334.  
  335. #define PTRACED(p)    ((p)->p_flag&(STRC|SPROCTR|SPROPEN))
  336.  
  337. /* Macro to reduce unnecessary calls to issig() */
  338.  
  339. #define    ISSIG(p, why) \
  340.   (((p)->p_cursig || !sigisempty(&(p)->p_sig) || ((p)->p_flag & SPRSTOP)) \
  341.     && issig(why))
  342.  
  343. /* Reasons for calling issig() */
  344.  
  345. #define    FORREAL        0    /* Usual side-effects */
  346. #define    JUSTLOOKING    1    /* Don't stop the process */
  347.  
  348. /* Macros for pid manipulation */
  349.  
  350. #define    PIDSHIFT        12        /* 2^PIDSHIFT >= NPROC */
  351. #define    PIDINDEXMAX        0x0fff        /* = 2^PIDSHIFT-1 */
  352. #define    PIDINCARMAX        0x7000        /* 3 bits for incarnation number as of 08/15/88 */
  353.  
  354. #define    GET_INDEX(PI_PID)    ((PI_PID)&(PIDINDEXMAX))
  355. #define    GET_INCAR(PI_PID)    (((unsigned)((PI_PID)&(PIDINCARMAX))) >> (PIDSHIFT))
  356. #define    INC_INCAR(PI_PID)    ((PI_PID) = (((unsigned)(PI_PID) + ((0x1)<<(PIDSHIFT)))&((PIDINDEXMAX)|(PIDINCARMAX))))
  357. #define INC_INDEX(PI_PID)    PUT_INDEX(PI_PID,(GET_INDEX(PI_PID)+1)%NPROC)
  358. #define    PUT_INCAR(PI_PID,INCAR)    ((PI_PID) = (((PI_PID)&(PIDINDEXMAX)) | (((INCAR)<<(PIDSHIFT))&(PIDINCARMAX))))
  359. #define PUT_INDEX(PI_PID,INDEX)    ((PI_PID) = (((PI_PID)&(PIDINCARMAX)) | ((INDEX)&(PIDINDEXMAX))))
  360.  
  361. #endif    /* _SYS_PROC_H */
  362.