home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 08 / 386bsd.asc next >
Text File  |  1991-07-23  |  10KB  |  190 lines

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