home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / bsdss4.tz / bsdss4 / bsdss / server / sys / proc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-25  |  11.3 KB  |  311 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1992 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon 
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    proc.h,v $
  29.  * Revision 2.2  92/05/25  14:46:01  rwd
  30.  *     Move modified fields to end so the structure is the same
  31.  *     as original 386BSD.  This allows ptrace code to run w/o
  32.  *     recompiling.
  33.  * 
  34.  * Revision 2.1  92/04/21  17:17:28  rwd
  35.  * BSDSS
  36.  * 
  37.  *
  38.  */
  39.  
  40. /*-
  41.  * Copyright (c) 1986, 1989, 1991 The Regents of the University of California.
  42.  * All rights reserved.
  43.  *
  44.  * Redistribution and use in source and binary forms, with or without
  45.  * modification, are permitted provided that the following conditions
  46.  * are met:
  47.  * 1. Redistributions of source code must retain the above copyright
  48.  *    notice, this list of conditions and the following disclaimer.
  49.  * 2. Redistributions in binary form must reproduce the above copyright
  50.  *    notice, this list of conditions and the following disclaimer in the
  51.  *    documentation and/or other materials provided with the distribution.
  52.  * 3. All advertising materials mentioning features or use of this software
  53.  *    must display the following acknowledgement:
  54.  *    This product includes software developed by the University of
  55.  *    California, Berkeley and its contributors.
  56.  * 4. Neither the name of the University nor the names of its contributors
  57.  *    may be used to endorse or promote products derived from this software
  58.  *    without specific prior written permission.
  59.  *
  60.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  61.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  64.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  65.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  66.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  67.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  69.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  70.  * SUCH DAMAGE.
  71.  *
  72.  *    @(#)proc.h    7.28 (Berkeley) 5/30/91
  73.  */
  74.  
  75. #ifndef _PROC_H_
  76. #define    _PROC_H_
  77.  
  78. #include <uxkern/import_mach.h>
  79. #include <sys/vmspace.h>
  80. #include <machine/proc.h>        /* machine-dependent proc substruct */
  81. #include <sys/queue.h>
  82.  
  83. /*
  84.  * One structure allocated per session.
  85.  */
  86. struct    session {
  87.     int    s_count;        /* ref cnt; pgrps in session */
  88.     struct    proc *s_leader;        /* session leader */
  89.     struct    vnode *s_ttyvp;        /* vnode of controlling terminal */
  90.     struct    tty *s_ttyp;        /* controlling terminal */
  91.     char    s_login[MAXLOGNAME];    /* setlogin() name */
  92. };
  93.  
  94. /*
  95.  * One structure allocated per process group.
  96.  */
  97. struct    pgrp {
  98.     struct    pgrp *pg_hforw;        /* forward link in hash bucket */
  99.     struct    proc *pg_mem;        /* pointer to pgrp members */
  100.     struct    session *pg_session;    /* pointer to session */
  101.     pid_t    pg_id;            /* pgrp id */
  102.     int    pg_jobc;    /* # procs qualifying pgrp for job control */
  103. };
  104.  
  105. /*
  106.  * Description of a process.
  107.  * This structure contains the information needed to manage a thread
  108.  * of control, known in UN*X as a process; it has references to substructures
  109.  * containing descriptions of things that the process uses, but may share
  110.  * with related processes.  The process structure and the substructures
  111.  * are always addressible except for those marked "(PROC ONLY)" below,
  112.  * which might be addressible only on a processor on which the process
  113.  * is running.
  114.  */
  115. struct    proc {
  116.     struct    proc *p_link;        /* doubly-linked run/sleep queue */
  117.     struct    proc *p_rlink;
  118.     struct    proc *p_nxt;        /* linked list of active procs */
  119.     struct    proc **p_prev;        /*    and zombies */
  120.  
  121.     /* substructures: */
  122.     struct    pcred *p_cred;        /* process owner's identity */
  123.     struct    filedesc *p_fd;        /* ptr to open files structure */
  124.     struct    pstats *p_stats;    /* accounting/statistics (PROC ONLY) */
  125.     struct    plimit *p_limit;    /* process limits */
  126.     struct    vmspace *p_vmspace;    /* address space */
  127.     struct    sigacts *p_sigacts;    /* signal actions, state (PROC ONLY) */
  128.  
  129. #define    p_ucred        p_cred->pc_ucred
  130. #define    p_rlimit    p_limit->pl_rlimit
  131.  
  132.     int    p_flag;
  133.     char    p_stat;
  134. /*    char    p_space; */
  135.  
  136.     pid_t    p_pid;        /* unique process id */
  137.     struct    proc *p_hash;    /* hashed based on p_pid for kill+exit+... */
  138.     struct    proc *p_pgrpnxt; /* pointer to next process in process group */
  139.     struct    proc *p_pptr;    /* pointer to process structure of parent */
  140.     struct    proc *p_osptr;    /* pointer to older sibling processes */
  141.  
  142. /* The following fields are all zeroed upon creation in fork */
  143. #define    p_startzero    p_ysptr
  144.     struct    proc *p_ysptr;    /* pointer to younger siblings */
  145.     struct    proc *p_cptr;    /* pointer to youngest living child */
  146.  
  147.     /* scheduling */
  148.     u_int    p_cpu;        /* cpu usage for scheduling */
  149.     int    p_cpticks;    /* ticks of cpu time */
  150.     fixpt_t    p_pctcpu;    /* %cpu for this process during p_time */
  151.     caddr_t p_wchan;    /* event process is awaiting */
  152.     u_int    p_time;        /* resident/nonresident time for swapping */
  153.     u_int    p_slptime;    /* time since last block */
  154.  
  155.     struct    itimerval p_realtimer;    /* alarm timer */
  156.     struct    timeval p_utime;    /* user time */
  157.     struct    timeval p_stime;    /* system time */
  158.  
  159.     int    p_traceflag;    /* kernel trace points */
  160.     struct    vnode *p_tracep;/* trace to vnode */
  161.  
  162.     int    p_sig;        /* signals pending to this process */
  163.  
  164. /* end area that is zeroed on creation */
  165. #define    p_endzero    p_startcopy
  166.  
  167. /* The following fields are all copied upon creation in fork */
  168.     sigset_t p_sigmask;    /* current signal mask */
  169. #define    p_startcopy    p_sigmask
  170.     sigset_t p_sigignore;    /* signals being ignored */
  171.     sigset_t p_sigcatch;    /* signals being caught by user */
  172.  
  173.     u_char    p_pri;        /* priority, negative is high */
  174.     u_char    p_usrpri;    /* user-priority based on p_cpu and p_nice */
  175.     char    p_nice;        /* nice for cpu usage */
  176. /*    char    p_space1; */
  177.  
  178.     struct     pgrp *p_pgrp;    /* pointer to process group */
  179.     char    p_comm[MAXCOMLEN+1];
  180.  
  181. /* end area that is copied on creation */
  182. #define    p_endcopy    p_wmesg
  183.     char    *p_wmesg;    /* reason for sleep */
  184.     mach_port_t p_thread;
  185.     struct    user *p_addr;    /* kernel virtual addr of u-area (PROC ONLY) */
  186.     swblk_t    p_swaddr;    /* disk address of u area when swapped */
  187.     int    *p_regs;    /* saved registers during syscall/trap */
  188.     struct    mdproc p_md;    /* any machine-dependent fields */
  189.  
  190.     u_short    p_xstat;    /* Exit status for wait; also stop signal */
  191.     u_short    p_dupfd;    /* sideways return value from fdopen XXX */
  192.     u_short    p_acflag;    /* accounting flags */
  193. /*    short    p_space2; */
  194.     struct    rusage *p_ru;    /* exit information XXX */
  195.  
  196. /* Put all new fields here to allow old ptrace driven user code
  197.  * which only accesses fields here and not in eproc to work.
  198.  */
  199.     struct    proc *p_tptr;    /* pointer to tracing process */
  200.     int    p_cursig;    /* signals pending to this process */
  201.  
  202.     mach_port_t p_task;
  203.     int p_master_lock;
  204.     int p_servers;
  205.     struct mutex p_lock;
  206.     int p_current_size;
  207.     mach_msg_header_t *p_reply_msg;
  208.     int p_ipl;
  209.     struct condition p_condition;
  210.     queue_chain_t p_sleep_link;
  211.     boolean_t p_timedout;
  212.     struct selbuf *p_sb;
  213.  
  214.     long    p_spare[4];    /* tmp spares to avoid shifting eproc */
  215. };
  216.  
  217. #define    p_session    p_pgrp->pg_session
  218. #define    p_pgid        p_pgrp->pg_id
  219.  
  220. /* MOVE TO ucred.h? */
  221. /*
  222.  * Shareable process credentials (always resident).
  223.  * This includes a reference to the current user credentials
  224.  * as well as real and saved ids that may be used to change ids.
  225.  */
  226. struct    pcred {
  227.     struct    ucred *pc_ucred;    /* current credentials */
  228.     uid_t    p_ruid;            /* real user id */
  229.     uid_t    p_svuid;        /* saved effective user id */
  230.     gid_t    p_rgid;            /* real group id */
  231.     gid_t    p_svgid;        /* saved effective group id */
  232.     int    p_refcnt;        /* number of references */
  233. };
  234.  
  235. /* stat codes */
  236. #define    SSLEEP    1        /* awaiting an event */
  237. #define    SWAIT    2        /* (abandoned state) */
  238. #define    SRUN    3        /* running */
  239. #define    SIDL    4        /* intermediate state in process creation */
  240. #define    SZOMB    5        /* intermediate state in process termination */
  241. #define    SSTOP    6        /* process being traced */
  242.  
  243. /* flag codes */
  244. #define    SLOAD    0x0000001    /* in core */
  245. #define    SSYS    0x0000002    /* swapper or pager process */
  246. #define    SSINTR    0x0000004    /* sleep is interruptible */
  247. #define    SCTTY    0x0000008    /* has a controlling terminal */
  248. #define    SPPWAIT    0x0000010    /* parent is waiting for child to exec/exit */
  249. #define SEXEC    0x0000020    /* process called exec */
  250. #define    STIMO    0x0000040    /* timing out during sleep */
  251. #define    SSEL    0x0000080    /* selecting; wakeup/waiting danger */
  252. #define    SWEXIT    0x0000100    /* working on exiting */
  253. #define    SNOCLDSTOP 0x0000200    /* no SIGCHLD when children stop */
  254. /* the following three should probably be changed into a hold count */
  255. #define    SLOCK    0x0000400    /* process being swapped out */
  256. #define    SKEEP    0x0000800    /* another flag to prevent swap out */
  257. #define    SPHYSIO    0x0001000    /* doing physical i/o */
  258. #define    STRC    0x0004000    /* process is being traced */
  259. #define    SWTED    0x0008000    /* another tracing flag */
  260. #define    SADVLCK    0x0040000    /* process may hold a POSIX advisory lock */
  261. /* the following should be moved to machine-dependent areas */
  262. #define    SOWEUPC    0x0002000    /* owe process an addupc() call at next ast */
  263. #ifdef HPUXCOMPAT
  264. #define    SHPUX    0x0010000    /* HP-UX process (HPUXCOMPAT) */
  265. #else
  266. #define    SHPUX    0        /* not HP-UX process (HPUXCOMPAT) */
  267. #endif
  268. #define SSTRC     0x0080000    /* process is tracing syscalls */
  269. #define SFTRC    0x0100000    /* trace state is inherited on fork */
  270. /* not currently in use (never set) */
  271. #define    SPAGE    0x0020000    /* process in page wait state */
  272.  
  273. #ifdef KERNEL
  274. /*
  275.  * We use process IDs <= PID_MAX;
  276.  * PID_MAX + 1 must also fit in a pid_t
  277.  * (used to represent "no process group").
  278.  */
  279. #define    PID_MAX        30000
  280. #define    NO_PID        30001
  281. #define    PIDHASH(pid)    ((pid) & pidhashmask)
  282.  
  283. #define SESS_LEADER(p)    ((p)->p_session->s_leader == (p))
  284. #define    SESSHOLD(s)    ((s)->s_count++)
  285. #define    SESSRELE(s)    { \
  286.         if (--(s)->s_count == 0) \
  287.             FREE(s, M_SESSION); \
  288.     }
  289.  
  290. extern    int pidhashmask;        /* in param.c */
  291. extern    struct proc *pidhash[];        /* in param.c */
  292. struct    proc *pfind();            /* find process by id */
  293. extern    struct pgrp *pgrphash[];    /* in param.c */
  294. struct     pgrp *pgfind();            /* find process group by id */
  295. struct    proc *zombproc, *allproc;    /* lists of procs in various states */
  296. extern    struct proc proc0;        /* process slot for swapper */
  297. struct    proc *initproc, *pageproc;    /* process slots for init, pager */
  298. extern    int nprocs, maxproc;        /* current and max number of procs */
  299. extern struct mutex allproc_lock;
  300.  
  301. #define    NQS    32        /* 32 run queues */
  302. struct    prochd {
  303.     struct    proc *ph_link;    /* linked list of running processes */
  304.     struct    proc *ph_rlink;
  305. } qs[NQS];
  306.  
  307. int    whichqs;        /* bit mask summarizing non-empty qs's */
  308. #endif    /* KERNEL */
  309.  
  310. #endif    /* !_PROC_H_ */
  311.