[BACK]Return to proc.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

Annotation of src/sys/sys/proc.h, Revision 1.29.2.3

1.29.2.3! mycroft     1: /*     $NetBSD: proc.h,v 1.29.2.2 1994/08/15 22:02:33 mycroft Exp $    */
1.29      cgd         2:
                      3: /*-
                      4:  * Copyright (c) 1986, 1989, 1991, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  * (c) UNIX System Laboratories, Inc.
                      7:  * All or some portions of this file are derived from material licensed
                      8:  * to the University of California by American Telephone and Telegraph
                      9:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     10:  * the permission of UNIX System Laboratories, Inc.
                     11:  *
                     12:  * Redistribution and use in source and binary forms, with or without
                     13:  * modification, are permitted provided that the following conditions
                     14:  * are met:
                     15:  * 1. Redistributions of source code must retain the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer.
                     17:  * 2. Redistributions in binary form must reproduce the above copyright
                     18:  *    notice, this list of conditions and the following disclaimer in the
                     19:  *    documentation and/or other materials provided with the distribution.
                     20:  * 3. All advertising materials mentioning features or use of this software
                     21:  *    must display the following acknowledgement:
                     22:  *     This product includes software developed by the University of
                     23:  *     California, Berkeley and its contributors.
                     24:  * 4. Neither the name of the University nor the names of its contributors
                     25:  *    may be used to endorse or promote products derived from this software
                     26:  *    without specific prior written permission.
                     27:  *
                     28:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     29:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     30:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     31:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     32:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     33:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     34:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     35:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     36:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     37:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     38:  * SUCH DAMAGE.
                     39:  *
                     40:  *     @(#)proc.h      8.8 (Berkeley) 1/21/94
                     41:  */
                     42:
                     43: #ifndef _SYS_PROC_H_
                     44: #define        _SYS_PROC_H_
                     45:
                     46: #include <machine/proc.h>              /* Machine-dependent proc substruct. */
                     47: #include <sys/select.h>                        /* For struct selinfo. */
                     48:
                     49: /*
                     50:  * One structure allocated per session.
                     51:  */
                     52: struct session {
                     53:        int     s_count;                /* Ref cnt; pgrps in session. */
                     54:        struct  proc *s_leader;         /* Session leader. */
                     55:        struct  vnode *s_ttyvp;         /* Vnode of controlling terminal. */
                     56:        struct  tty *s_ttyp;            /* Controlling terminal. */
                     57:        char    s_login[MAXLOGNAME];    /* Setlogin() name. */
                     58: };
                     59:
                     60: /*
                     61:  * One structure allocated per process group.
                     62:  */
                     63: struct pgrp {
                     64:        struct  pgrp *pg_hforw;         /* Forward link in hash bucket. */
                     65:        struct  proc *pg_mem;           /* Pointer to pgrp members. */
                     66:        struct  session *pg_session;    /* Pointer to session. */
                     67:        pid_t   pg_id;                  /* Pgrp id. */
                     68:        int     pg_jobc;        /* # procs qualifying pgrp for job control */
                     69: };
                     70:
                     71: /*
                     72:  * Description of a process.
                     73:  *
                     74:  * This structure contains the information needed to manage a thread of
                     75:  * control, known in UN*X as a process; it has references to substructures
                     76:  * containing descriptions of things that the process uses, but may share
                     77:  * with related processes.  The process structure and the substructures
                     78:  * are always addressible except for those marked "(PROC ONLY)" below,
                     79:  * which might be addressible only on a processor on which the process
                     80:  * is running.
                     81:  */
                     82: struct proc {
                     83:        struct  proc *p_forw;           /* Doubly-linked run/sleep queue. */
                     84:        struct  proc *p_back;
                     85:        struct  proc *p_next;           /* Linked list of active procs */
                     86:        struct  proc **p_prev;          /*    and zombies. */
                     87:
                     88:        /* substructures: */
                     89:        struct  pcred *p_cred;          /* Process owner's identity. */
                     90:        struct  filedesc *p_fd;         /* Ptr to open files structure. */
                     91:        struct  pstats *p_stats;        /* Accounting/statistics (PROC ONLY). */
                     92:        struct  plimit *p_limit;        /* Process limits. */
                     93:        struct  vmspace *p_vmspace;     /* Address space. */
                     94:        struct  sigacts *p_sigacts;     /* Signal actions, state (PROC ONLY). */
                     95:
                     96: #define        p_ucred         p_cred->pc_ucred
                     97: #define        p_rlimit        p_limit->pl_rlimit
                     98:
                     99:        int     p_flag;                 /* P_* flags. */
                    100:        char    p_stat;                 /* S* process status. */
                    101:        char    p_pad1[3];
                    102:
                    103:        pid_t   p_pid;                  /* Process identifier. */
                    104:        struct  proc *p_hash;    /* Hashed based on p_pid for kill+exit+... */
                    105:        struct  proc *p_pgrpnxt; /* Pointer to next process in process group. */
                    106:        struct  proc *p_pptr;    /* Pointer to process structure of parent. */
                    107:        struct  proc *p_osptr;   /* Pointer to older sibling processes. */
                    108:
                    109: /* The following fields are all zeroed upon creation in fork. */
                    110: #define        p_startzero     p_ysptr
                    111:
                    112:        struct  proc *p_ysptr;   /* Pointer to younger siblings. */
                    113:        struct  proc *p_cptr;    /* Pointer to youngest living child. */
                    114:        pid_t   p_oppid;         /* Save parent pid during ptrace. XXX */
                    115:        int     p_dupfd;         /* Sideways return value from fdopen. XXX */
                    116:
                    117:        /* scheduling */
                    118:        u_int   p_estcpu;        /* Time averaged value of p_cpticks. */
                    119:        int     p_cpticks;       /* Ticks of cpu time. */
                    120:        fixpt_t p_pctcpu;        /* %cpu for this process during p_swtime */
                    121:        void    *p_wchan;        /* Sleep address. */
                    122:        char    *p_wmesg;        /* Reason for sleep. */
                    123:        u_int   p_swtime;        /* Time swapped in or out. */
                    124:        u_int   p_slptime;       /* Time since last blocked. */
                    125:
                    126:        struct  itimerval p_realtimer;  /* Alarm timer. */
                    127:        struct  timeval p_rtime;        /* Real time. */
                    128:        u_quad_t p_uticks;              /* Statclock hits in user mode. */
                    129:        u_quad_t p_sticks;              /* Statclock hits in system mode. */
                    130:        u_quad_t p_iticks;              /* Statclock hits processing intr. */
                    131:
                    132:        int     p_traceflag;            /* Kernel trace points. */
                    133:        struct  vnode *p_tracep;        /* Trace to vnode. */
                    134:
                    135:        int     p_siglist;              /* Signals arrived but not delivered. */
                    136:
                    137:        struct  vnode *p_textvp;        /* Vnode of executable. */
                    138:
                    139:        int     p_holdcnt;              /* If non-zero, don't swap. */
                    140:
                    141:        long    p_spare[4];             /* pad to 256, avoid shifting eproc. */
                    142:
                    143: /* End area that is zeroed on creation. */
                    144: #define        p_endzero       p_startcopy
                    145:
                    146: /* The following fields are all copied upon creation in fork. */
                    147: #define        p_startcopy     p_sigmask
                    148:
                    149:        sigset_t p_sigmask;     /* Current signal mask. */
                    150:        sigset_t p_sigignore;   /* Signals being ignored. */
                    151:        sigset_t p_sigcatch;    /* Signals being caught by user. */
                    152:
                    153:        u_char  p_priority;     /* Process priority. */
                    154:        u_char  p_usrpri;       /* User-priority based on p_cpu and p_nice. */
                    155:        char    p_nice;         /* Process "nice" value. */
                    156:        char    p_comm[MAXCOMLEN+1];
                    157:        u_char  p_emul;         /* Operating system being emulated. */
                    158:
                    159:        struct  pgrp *p_pgrp;   /* Pointer to process group. */
                    160:
                    161: /* End area that is copied on creation. */
                    162: #define        p_endcopy       p_thread
                    163:
                    164:        int     p_thread;       /* Id for this "thread"; Mach glue. XXX */
                    165:        struct  user *p_addr;   /* Kernel virtual addr of u-area (PROC ONLY). */
                    166:        struct  mdproc p_md;    /* Any machine-dependent fields. */
                    167:
                    168:        u_short p_xstat;        /* Exit status for wait; also stop signal. */
                    169:        u_short p_acflag;       /* Accounting flags. */
                    170:        struct  rusage *p_ru;   /* Exit information. XXX */
                    171: };
                    172:
                    173: #define        p_session       p_pgrp->pg_session
                    174: #define        p_pgid          p_pgrp->pg_id
                    175:
                    176: /* Status values. */
                    177: #define        SIDL    1               /* Process being created by fork. */
                    178: #define        SRUN    2               /* Currently runnable. */
                    179: #define        SSLEEP  3               /* Sleeping on an address. */
                    180: #define        SSTOP   4               /* Process debugging or suspension. */
                    181: #define        SZOMB   5               /* Awaiting collection by parent. */
                    182:
                    183: /* These flags are kept in p_flags. */
                    184: #define        P_ADVLOCK       0x00001 /* Process may hold a POSIX advisory lock. */
                    185: #define        P_CONTROLT      0x00002 /* Has a controlling terminal. */
                    186: #define        P_INMEM         0x00004 /* Loaded into memory. */
                    187: #define        P_NOCLDSTOP     0x00008 /* No SIGCHLD when children stop. */
                    188: #define        P_PPWAIT        0x00010 /* Parent is waiting for child to exec/exit. */
                    189: #define        P_PROFIL        0x00020 /* Has started profiling. */
                    190: #define        P_SELECT        0x00040 /* Selecting; wakeup/waiting danger. */
                    191: #define        P_SINTR         0x00080 /* Sleep is interruptible. */
                    192: #define        P_SUGID         0x00100 /* Had set id privileges since last exec. */
                    193: #define        P_SYSTEM        0x00200 /* System proc: no sigs, stats or swapping. */
                    194: #define        P_TIMEOUT       0x00400 /* Timing out during sleep. */
                    195: #define        P_TRACED        0x00800 /* Debugged process being traced. */
                    196: #define        P_WAITED        0x01000 /* Debugging process has waited for child. */
                    197: #define        P_WEXIT         0x02000 /* Working on exiting. */
                    198: #define        P_EXEC          0x04000 /* Process called exec. */
                    199:
                    200: /* Should be moved to machine-dependent areas. */
                    201: #define        P_OWEUPC        0x08000 /* Owe process an addupc() call at next ast. */
                    202:
                    203: /* XXX Not sure what to do with these, yet. */
                    204: #define        P_FSTRACE       0x10000 /* tracing via file system (elsewhere?) */
                    205: #define        P_SSTEP         0x20000 /* process needs single-step fixup ??? */
                    206:
                    207: /*
                    208:  * Definitions for the p_emul flag.
                    209:  */
                    210: #define        EMUL_NETBSD     0               /* default, naturally */
                    211: #define        EMUL_SUNOS      1               /* sunos 4.x binaries */
                    212: #define        EMUL_HPUX       2               /* HPUX binaries */
                    213: #define        EMUL_ULTRIX     3               /* Ultrix binaries */
1.29.2.3! mycroft   214: #define        EMUL_IBCS2_ELF  4               /* Intel Binary compat; SVR4 */
        !           215: #define        EMUL_IBCS2_COFF 5               /* Intel Binary compat; SCO Unix */
        !           216: #define        EMUL_IBCS2_XOUT 6               /* Intel Binary compat; SCO Xenix */
        !           217: #define        EMUL_OSF1       7               /* OSF/1 binaries */
1.29      cgd       218:
                    219: /*
                    220:  * MOVE TO ucred.h?
                    221:  *
                    222:  * Shareable process credentials (always resident).  This includes a reference
                    223:  * to the current user credentials as well as real and saved ids that may be
                    224:  * 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: #ifdef KERNEL
                    236: /*
                    237:  * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
                    238:  * as it is used to represent "no process group".
                    239:  */
                    240: #define        PID_MAX         30000
                    241: #define        NO_PID          30001
                    242: #define        PIDHASH(pid)    ((pid) & pidhashmask)
                    243:
                    244: #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
                    245: #define        SESSHOLD(s)     ((s)->s_count++)
                    246: #define        SESSRELE(s) {                                                   \
                    247:        if (--(s)->s_count == 0)                                        \
                    248:                FREE(s, M_SESSION);                                     \
                    249: }
                    250:
                    251: extern struct proc *pidhash[];         /* In param.c. */
                    252: extern struct pgrp *pgrphash[];                /* In param.c. */
                    253: extern struct proc *curproc;           /* Current running proc. */
                    254: extern struct proc proc0;              /* Process slot for swapper. */
                    255: extern int nprocs, maxproc;            /* Current and max number of procs. */
                    256: extern int pidhashmask;                        /* In param.c. */
                    257:
                    258: volatile struct proc *allproc;         /* List of active procs. */
                    259: struct proc *zombproc;                 /* List of zombie procs. */
                    260: struct proc *initproc, *pageproc;      /* Process slots for init, pager. */
                    261:
                    262: #define        NQS     32                      /* 32 run queues. */
                    263: int    whichqs;                        /* Bit mask summary of non-empty Q's. */
                    264: struct prochd {
                    265:        struct  proc *ph_link;          /* Linked list of running processes. */
                    266:        struct  proc *ph_rlink;
                    267: } qs[NQS];
                    268:
                    269: struct proc *pfind __P((pid_t));       /* Find process by id. */
                    270: struct pgrp *pgfind __P((pid_t));      /* Find process group by id. */
                    271:
                    272: void   fixjobc __P((struct proc *p, struct pgrp *pgrp, int entering));
                    273: void   mi_switch __P((void));
                    274: void   resetpriority __P((struct proc *));
                    275: void   setrunnable __P((struct proc *));
                    276: void   setrunqueue __P((struct proc *));
                    277: void   sleep __P((void *chan, int pri));
                    278: int    tsleep __P((void *chan, int pri, char *wmesg, int timo));
                    279: void   unsleep __P((struct proc *));
                    280: void   wakeup __P((void *chan));
                    281: #endif /* KERNEL */
                    282: #endif /* !_SYS_PROC_H_ */

CVSweb <webmaster@jp.NetBSD.org>