home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-inc-bin.lha / include / sys / proc.h < prev    next >
C/C++ Source or Header  |  1996-10-12  |  9KB  |  242 lines

  1. /*-
  2.  * Copyright (c) 1986, 1989, 1991 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)proc.h    7.28 (Berkeley) 5/30/91
  34.  */
  35.  
  36. #ifndef _PROC_H_
  37. #define    _PROC_H_
  38.  
  39. #include <machine/proc.h>        /* machine-dependent proc substruct */
  40.  
  41. /*
  42.  * One structure allocated per session.
  43.  */
  44. struct    session {
  45.     int    s_count;        /* ref cnt; pgrps in session */
  46.     struct    proc *s_leader;        /* session leader */
  47.     struct    vnode *s_ttyvp;        /* vnode of controlling terminal */
  48.     struct    tty *s_ttyp;        /* controlling terminal */
  49.     char    s_login[MAXLOGNAME];    /* setlogin() name */
  50. };
  51.  
  52. /*
  53.  * One structure allocated per process group.
  54.  */
  55. struct    pgrp {
  56.     struct    pgrp *pg_hforw;        /* forward link in hash bucket */
  57.     struct    proc *pg_mem;        /* pointer to pgrp members */
  58.     struct    session *pg_session;    /* pointer to session */
  59.     pid_t    pg_id;            /* pgrp id */
  60.     int    pg_jobc;    /* # procs qualifying pgrp for job control */
  61. };
  62.  
  63. /*
  64.  * Description of a process.
  65.  * This structure contains the information needed to manage a thread
  66.  * of control, known in UN*X as a process; it has references to substructures
  67.  * containing descriptions of things that the process uses, but may share
  68.  * with related processes.  The process structure and the substructures
  69.  * are always addressible except for those marked "(PROC ONLY)" below,
  70.  * which might be addressible only on a processor on which the process
  71.  * is running.
  72.  */
  73. struct    proc {
  74.     struct    proc *p_link;        /* doubly-linked run/sleep queue */
  75.     struct    proc *p_rlink;
  76.     struct    proc *p_nxt;        /* linked list of active procs */
  77.     struct    proc **p_prev;        /*    and zombies */
  78.  
  79.     /* substructures: */
  80.     struct    pcred *p_cred;        /* process owner's identity */
  81.     struct    filedesc *p_fd;        /* ptr to open files structure */
  82.     struct    pstats *p_stats;    /* accounting/statistics (PROC ONLY) */
  83.     struct    plimit *p_limit;    /* process limits */
  84.     struct    vmspace *p_vmspace;    /* address space */
  85.     struct    sigacts *p_sigacts;    /* signal actions, state (PROC ONLY) */
  86.  
  87. #define    p_ucred        p_cred->pc_ucred
  88. #define    p_rlimit    p_limit->pl_rlimit
  89.  
  90.     int    p_flag;
  91.     char    p_stat;
  92. /*    char    p_space; */
  93.  
  94.     pid_t    p_pid;        /* unique process id */
  95.     struct    proc *p_hash;    /* hashed based on p_pid for kill+exit+... */
  96.     struct    proc *p_pgrpnxt; /* pointer to next process in process group */
  97.     struct    proc *p_pptr;    /* pointer to process structure of parent */
  98.     struct    proc *p_osptr;    /* pointer to older sibling processes */
  99.  
  100. /* The following fields are all zeroed upon creation in fork */
  101. #define    p_startzero    p_ysptr
  102.     struct    proc *p_ysptr;    /* pointer to younger siblings */
  103.     struct    proc *p_cptr;    /* pointer to youngest living child */
  104.  
  105.     /* scheduling */
  106.     u_int    p_cpu;        /* cpu usage for scheduling */
  107.     int    p_cpticks;    /* ticks of cpu time */
  108.     fixpt_t    p_pctcpu;    /* %cpu for this process during p_time */
  109.     caddr_t p_wchan;    /* event process is awaiting */
  110.     u_int    p_time;        /* resident/nonresident time for swapping */
  111.     u_int    p_slptime;    /* time since last block */
  112.  
  113.     struct    itimerval p_realtimer;    /* alarm timer */
  114.     struct    timeval p_utime;    /* user time */
  115.     struct    timeval p_stime;    /* system time */
  116.  
  117.     int    p_sig;        /* signals pending to this process */
  118.  
  119. /* end area that is zeroed on creation */
  120. #define    p_endzero    p_startcopy
  121.  
  122. /* The following fields are all copied upon creation in fork */
  123.     sigset_t p_sigmask;    /* current signal mask */
  124. #define    p_startcopy    p_sigmask
  125.     sigset_t p_sigignore;    /* signals being ignored */
  126.     sigset_t p_sigcatch;    /* signals being caught by user */
  127.  
  128.     u_char    p_pri;        /* priority, negative is high */
  129.     u_char    p_usrpri;    /* user-priority based on p_cpu and p_nice */
  130.     char    p_nice;        /* nice for cpu usage */
  131. /*    char    p_space1; */
  132.  
  133.     struct     pgrp *p_pgrp;    /* pointer to process group */
  134.     char    p_comm[MAXCOMLEN+1];
  135.  
  136. /* end area that is copied on creation */
  137. #define    p_endcopy    p_wmesg
  138.     char    *p_wmesg;    /* reason for sleep */
  139.     struct Process *p_process; /* id for this AmigaOS process */
  140.     struct    user *p_addr;    /* addr of u-area (points at p_user) */
  141.     int    *p_regs;    /* saved registers during syscall/trap */
  142.  
  143.     u_short    p_xstat;    /* Exit status for wait; also stop signal */
  144.     u_short    p_dupfd;    /* sideways return value from fdopen XXX */
  145.     u_short    p_acflag;    /* accounting flags */
  146.  
  147.  
  148. };
  149.  
  150. #define    p_session    p_pgrp->pg_session
  151. #define    p_pgid        p_pgrp->pg_id
  152.  
  153. /* MOVE TO ucred.h? */
  154. /*
  155.  * Shareable process credentials (always resident).
  156.  * This includes a reference to the current user credentials
  157.  * as well as real and saved ids that may be used to change ids.
  158.  */
  159. struct    pcred {
  160.     struct    ucred *pc_ucred;    /* current credentials */
  161.     uid_t    p_ruid;            /* real user id */
  162.     uid_t    p_svuid;        /* saved effective user id */
  163.     gid_t    p_rgid;            /* real group id */
  164.     gid_t    p_svgid;        /* saved effective group id */
  165.     int    p_refcnt;        /* number of references */
  166. };
  167.  
  168. /* stat codes */
  169. #define    SSLEEP    1        /* awaiting an event */
  170. #define    SWAIT    2        /* (abandoned state) */
  171. #define    SRUN    3        /* running */
  172. #define    SIDL    4        /* intermediate state in process creation */
  173. #define    SZOMB    5        /* intermediate state in process termination */
  174. #define    SSTOP    6        /* process being traced */
  175.  
  176. /* flag codes */
  177. #define    SLOAD    0x0000001    /* in core */
  178. #define    SSYS    0x0000002    /* swapper or pager process */
  179. #define    SSINTR    0x0000004    /* sleep is interruptible */
  180. #define    SCTTY    0x0000008    /* has a controlling terminal */
  181. #define    SPPWAIT    0x0000010    /* parent is waiting for child to exec/exit */
  182. #define SEXEC    0x0000020    /* process called exec */
  183. #define    STIMO    0x0000040    /* timing out during sleep */
  184. #define    SSEL    0x0000080    /* selecting; wakeup/waiting danger */
  185. #define    SWEXIT    0x0000100    /* working on exiting */
  186. #define    SNOCLDSTOP 0x0000200    /* no SIGCHLD when children stop */
  187. /* the following three should probably be changed into a hold count */
  188. #define    SLOCK    0x0000400    /* process being swapped out */
  189. #define    SKEEP    0x0000800    /* another flag to prevent swap out */
  190. #define    SPHYSIO    0x0001000    /* doing physical i/o */
  191. #define    STRC    0x0004000    /* process is being traced */
  192. #define    SWTED    0x0008000    /* another tracing flag */
  193. #define    SADVLCK    0x0040000    /* process may hold a POSIX advisory lock */
  194. /* the following should be moved to machine-dependent areas */
  195. #define    SOWEUPC    0x0002000    /* owe process an addupc() call at next ast */
  196. #ifdef HPUXCOMPAT
  197. #define    SHPUX    0x0010000    /* HP-UX process (HPUXCOMPAT) */
  198. #else
  199. #define    SHPUX    0        /* not HP-UX process (HPUXCOMPAT) */
  200. #endif
  201. /* not currently in use (never set) */
  202. #define    SPAGE    0x0020000    /* process in page wait state */
  203.  
  204. #ifdef _KERNEL
  205. /*
  206.  * We use process IDs <= PID_MAX;
  207.  * PID_MAX + 1 must also fit in a pid_t
  208.  * (used to represent "no process group").
  209.  */
  210. #define    PID_MAX        30000
  211. #define    NO_PID        30001
  212. #define    PIDHASH(pid)    ((pid) & pidhashmask)
  213.  
  214. #define SESS_LEADER(p)    ((p)->p_session->s_leader == (p))
  215. #define    SESSHOLD(s)    ((s)->s_count++)
  216. #define    SESSRELE(s)    { \
  217.         if (--(s)->s_count == 0) \
  218.             FREE(s, M_SESSION); \
  219.     }
  220.  
  221. extern    int pidhashmask;        /* in param.c */
  222. extern    struct proc *pidhash[];        /* in param.c */
  223. struct    proc *pfind();            /* find process by id */
  224. extern    struct pgrp *pgrphash[];    /* in param.c */
  225. struct     pgrp *pgfind();            /* find process group by id */
  226. struct    proc *zombproc, *allproc;    /* lists of procs in various states */
  227. extern    struct proc proc0;        /* process slot for swapper */
  228. struct    proc *initproc, *pageproc;    /* process slots for init, pager */
  229. extern    struct proc *curproc;        /* current running proc */
  230. extern    int nprocs, maxproc;        /* current and max number of procs */
  231.  
  232. #define    NQS    32        /* 32 run queues */
  233. struct    prochd {
  234.     struct    proc *ph_link;    /* linked list of running processes */
  235.     struct    proc *ph_rlink;
  236. } qs[NQS];
  237.  
  238. int    whichqs;        /* bit mask summarizing non-empty qs's */
  239. #endif    /* _KERNEL */
  240.  
  241. #endif    /* !_PROC_H_ */
  242.