2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/sysctl.h>
34 #include <sys/malloc.h>
36 #include <sys/vnode.h>
38 #include <sys/filedesc.h>
40 #include <sys/dsched.h>
41 #include <sys/signalvar.h>
42 #include <sys/spinlock.h>
43 #include <sys/random.h>
44 #include <sys/vnode.h>
49 #include <vm/vm_map.h>
51 #include <machine/smp.h>
53 #include <sys/refcount.h>
54 #include <sys/spinlock2.h>
57 * Hash table size must be a power of two and is not currently dynamically
58 * sized. There is a trade-off between the linear scans which must iterate
59 * all HSIZE elements and the number of elements which might accumulate
60 * within each hash chain.
62 #define ALLPROC_HSIZE 256
63 #define ALLPROC_HMASK (ALLPROC_HSIZE - 1)
64 #define ALLPROC_HASH(pid) (pid & ALLPROC_HMASK)
65 #define PGRP_HASH(pid) (pid & ALLPROC_HMASK)
66 #define SESS_HASH(pid) (pid & ALLPROC_HMASK)
69 * pid_doms[] management, used to control how quickly a PID can be recycled.
70 * Must be a multiple of ALLPROC_HSIZE for the proc_makepid() inner loops.
72 * WARNING! PIDDOM_DELAY should not be defined > 20 or so unless you change
73 * the array from int8_t's to int16_t's.
75 #define PIDDOM_COUNT 10 /* 10 pids per domain - reduce array size */
76 #define PIDDOM_DELAY 10 /* min 10 seconds after exit before reuse */
77 #define PIDDOM_SCALE 10 /* (10,000*SCALE)/sec performance guarantee */
78 #define PIDSEL_DOMAINS (PID_MAX * PIDDOM_SCALE / PIDDOM_COUNT / \
79 ALLPROC_HSIZE * ALLPROC_HSIZE)
82 int allproc_hsize = ALLPROC_HSIZE;
84 LIST_HEAD(pidhashhead, proc);
86 static MALLOC_DEFINE(M_PGRP, "pgrp", "process group header");
87 MALLOC_DEFINE(M_SESSION, "session", "session header");
88 MALLOC_DEFINE(M_PROC, "proc", "Proc structures");
89 MALLOC_DEFINE(M_LWP, "lwp", "lwp structures");
90 MALLOC_DEFINE(M_SUBPROC, "subproc", "Proc sub-structures");
92 int ps_showallprocs = 1;
93 static int ps_showallthreads = 1;
94 SYSCTL_INT(_security, OID_AUTO, ps_showallprocs, CTLFLAG_RW,
96 "Unprivileged processes can see processes with different UID/GID");
97 SYSCTL_INT(_security, OID_AUTO, ps_showallthreads, CTLFLAG_RW,
98 &ps_showallthreads, 0,
99 "Unprivileged processes can see kernel threads");
100 static u_int pid_domain_skips;
101 SYSCTL_UINT(_kern, OID_AUTO, pid_domain_skips, CTLFLAG_RW,
102 &pid_domain_skips, 0,
103 "Number of pid_doms[] skipped");
104 static u_int pid_inner_skips;
105 SYSCTL_UINT(_kern, OID_AUTO, pid_inner_skips, CTLFLAG_RW,
107 "Number of pid_doms[] skipped");
109 static void orphanpg(struct pgrp *pg);
110 static void proc_makepid(struct proc *p, int random_offset);
113 * Process related lists (for proc_token, allproc, allpgrp, and allsess)
115 typedef struct procglob procglob_t;
117 static procglob_t procglob[ALLPROC_HSIZE];
120 * We try our best to avoid recycling a PID too quickly. We do this by
121 * storing (uint8_t)time_second in the related pid domain on-reap and then
122 * using that to skip-over the domain on-allocate.
124 * This array has to be fairly large to support a high fork/exec rate.
125 * A ~100,000 entry array will support a 10-second reuse latency at
126 * 10,000 execs/second, worst case. Best-case multiply by PIDDOM_COUNT
127 * (approximately 100,000 execs/second).
129 * Currently we allocate around a megabyte, making the worst-case fork
130 * rate around 100,000/second.
132 static uint8_t *pid_doms;
135 * Random component to nextpid generation. We mix in a random factor to make
136 * it a little harder to predict. We sanity check the modulus value to avoid
137 * doing it in critical paths. Don't let it be too small or we pointlessly
138 * waste randomness entropy, and don't let it be impossibly large. Using a
139 * modulus that is too big causes a LOT more process table scans and slows
140 * down fork processing as the pidchecked caching is defeated.
142 static int randompid = 0;
146 pcredcache(struct ucred *cr, struct proc *p)
148 if (cr != p->p_ucred) {
151 spin_lock(&p->p_spin);
152 if ((cr = p->p_ucred) != NULL)
154 spin_unlock(&p->p_spin);
163 sysctl_kern_randompid(SYSCTL_HANDLER_ARGS)
168 error = sysctl_handle_int(oidp, &pid, 0, req);
169 if (error || !req->newptr)
171 if (pid < 0 || pid > PID_MAX - 100) /* out of range */
173 else if (pid < 2) /* NOP */
175 else if (pid < 100) /* Make it reasonable */
181 SYSCTL_PROC(_kern, OID_AUTO, randompid, CTLTYPE_INT|CTLFLAG_RW,
182 0, 0, sysctl_kern_randompid, "I", "Random PID modulus");
185 * Initialize global process hashing structures.
187 * These functions are ONLY called from the low level boot code and do
188 * not lock their operations.
196 * Allocate dynamically. This array can be large (~1MB) so don't
197 * waste boot loader space.
199 pid_doms = kmalloc(sizeof(pid_doms[0]) * PIDSEL_DOMAINS,
200 M_PROC, M_WAITOK | M_ZERO);
203 * Avoid unnecessary stalls due to pid_doms[] values all being
204 * the same. Make sure that the allocation of pid 1 and pid 2
207 for (i = 0; i < PIDSEL_DOMAINS; ++i)
208 pid_doms[i] = (int8_t)i - (int8_t)(PIDDOM_DELAY + 1);
213 for (i = 0; i < ALLPROC_HSIZE; ++i) {
214 procglob_t *prg = &procglob[i];
215 LIST_INIT(&prg->allproc);
216 LIST_INIT(&prg->allsess);
217 LIST_INIT(&prg->allpgrp);
218 lwkt_token_init(&prg->proc_token, "allproc");
224 procinsertinit(struct proc *p)
226 LIST_INSERT_HEAD(&procglob[ALLPROC_HASH(p->p_pid)].allproc,
231 pgrpinsertinit(struct pgrp *pg)
233 LIST_INSERT_HEAD(&procglob[ALLPROC_HASH(pg->pg_id)].allpgrp,
238 sessinsertinit(struct session *sess)
240 LIST_INSERT_HEAD(&procglob[ALLPROC_HASH(sess->s_sid)].allsess,
245 * Process hold/release support functions. Called via the PHOLD(),
246 * PRELE(), and PSTALL() macros.
248 * p->p_lock is a simple hold count with a waiting interlock. No wakeup()
249 * is issued unless someone is actually waiting for the process.
251 * Most holds are short-term, allowing a process scan or other similar
252 * operation to access a proc structure without it getting ripped out from
253 * under us. procfs and process-list sysctl ops also use the hold function
254 * interlocked with various p_flags to keep the vmspace intact when reading
255 * or writing a user process's address space.
257 * There are two situations where a hold count can be longer. Exiting lwps
258 * hold the process until the lwp is reaped, and the parent will hold the
259 * child during vfork()/exec() sequences while the child is marked P_PPWAIT.
261 * The kernel waits for the hold count to drop to 0 (or 1 in some cases) at
262 * various critical points in the fork/exec and exit paths before proceeding.
264 #define PLOCK_ZOMB 0x20000000
265 #define PLOCK_WAITING 0x40000000
266 #define PLOCK_MASK 0x1FFFFFFF
269 pstall(struct proc *p, const char *wmesg, int count)
277 if ((o & PLOCK_MASK) <= count)
279 n = o | PLOCK_WAITING;
280 tsleep_interlock(&p->p_lock, 0);
283 * If someone is trying to single-step the process during
284 * an exec or an exit they can deadlock us because procfs
285 * sleeps with the process held.
288 if (p->p_flags & P_INEXEC) {
290 } else if (p->p_flags & P_POSTEXIT) {
291 spin_lock(&p->p_spin);
294 spin_unlock(&p->p_spin);
299 if (atomic_cmpset_int(&p->p_lock, o, n)) {
300 tsleep(&p->p_lock, PINTERLOCKED, wmesg, 0);
306 phold(struct proc *p)
308 atomic_add_int(&p->p_lock, 1);
312 * WARNING! On last release (p) can become instantly invalid due to
316 prele(struct proc *p)
324 if (atomic_cmpset_int(&p->p_lock, 1, 0))
332 KKASSERT((o & PLOCK_MASK) > 0);
334 n = (o - 1) & ~PLOCK_WAITING;
335 if (atomic_cmpset_int(&p->p_lock, o, n)) {
336 if (o & PLOCK_WAITING)
344 * Hold and flag serialized for zombie reaping purposes.
346 * This function will fail if it has to block, returning non-zero with
347 * neither the flag set or the hold count bumped. Note that (p) may
348 * not be valid in this case if the caller does not have some other
351 * This function does not block on other PHOLD()s, only on other
354 * Zero is returned on success. The hold count will be incremented and
355 * the serialization flag acquired. Note that serialization is only against
356 * other pholdzomb() calls, not against phold() calls.
359 pholdzomb(struct proc *p)
367 if (atomic_cmpset_int(&p->p_lock, 0, PLOCK_ZOMB | 1))
376 if ((o & PLOCK_ZOMB) == 0) {
377 n = (o + 1) | PLOCK_ZOMB;
378 if (atomic_cmpset_int(&p->p_lock, o, n))
381 KKASSERT((o & PLOCK_MASK) > 0);
382 n = o | PLOCK_WAITING;
383 tsleep_interlock(&p->p_lock, 0);
384 if (atomic_cmpset_int(&p->p_lock, o, n)) {
385 tsleep(&p->p_lock, PINTERLOCKED, "phldz", 0);
386 /* (p) can be ripped out at this point */
394 * Release PLOCK_ZOMB and the hold count, waking up any waiters.
396 * WARNING! On last release (p) can become instantly invalid due to
400 prelezomb(struct proc *p)
408 if (atomic_cmpset_int(&p->p_lock, PLOCK_ZOMB | 1, 0))
414 KKASSERT(p->p_lock & PLOCK_ZOMB);
417 KKASSERT((o & PLOCK_MASK) > 0);
419 n = (o - 1) & ~(PLOCK_ZOMB | PLOCK_WAITING);
420 if (atomic_cmpset_int(&p->p_lock, o, n)) {
421 if (o & PLOCK_WAITING)
429 * Is p an inferior of the current process?
434 inferior(struct proc *p)
439 lwkt_gettoken_shared(&p->p_token);
440 while (p != curproc) {
442 lwkt_reltoken(&p->p_token);
447 lwkt_reltoken(&p->p_token);
449 lwkt_gettoken_shared(&p2->p_token);
452 lwkt_reltoken(&p->p_token);
459 * Locate a process by number. The returned process will be referenced and
460 * must be released with PRELE().
467 struct proc *p = curproc;
472 * Shortcut the current process
474 if (p && p->p_pid == pid) {
480 * Otherwise find it in the hash table.
482 n = ALLPROC_HASH(pid);
485 lwkt_gettoken_shared(&prg->proc_token);
486 LIST_FOREACH(p, &prg->allproc, p_list) {
487 if (p->p_stat == SZOMB)
489 if (p->p_pid == pid) {
491 lwkt_reltoken(&prg->proc_token);
495 lwkt_reltoken(&prg->proc_token);
501 * Locate a process by number. The returned process is NOT referenced.
502 * The result will not be stable and is typically only used to validate
503 * against a process that the caller has in-hand.
510 struct proc *p = curproc;
515 * Shortcut the current process
517 if (p && p->p_pid == pid)
521 * Otherwise find it in the hash table.
523 n = ALLPROC_HASH(pid);
526 lwkt_gettoken_shared(&prg->proc_token);
527 LIST_FOREACH(p, &prg->allproc, p_list) {
528 if (p->p_stat == SZOMB)
530 if (p->p_pid == pid) {
531 lwkt_reltoken(&prg->proc_token);
535 lwkt_reltoken(&prg->proc_token);
541 * Locate a process on the zombie list. Return a process or NULL.
542 * The returned process will be referenced and the caller must release
545 * No other requirements.
550 struct proc *p = curproc;
555 * Shortcut the current process
557 if (p && p->p_pid == pid) {
563 * Otherwise find it in the hash table.
565 n = ALLPROC_HASH(pid);
568 lwkt_gettoken_shared(&prg->proc_token);
569 LIST_FOREACH(p, &prg->allproc, p_list) {
570 if (p->p_stat != SZOMB)
572 if (p->p_pid == pid) {
574 lwkt_reltoken(&prg->proc_token);
578 lwkt_reltoken(&prg->proc_token);
585 pgref(struct pgrp *pgrp)
587 refcount_acquire(&pgrp->pg_refs);
591 pgrel(struct pgrp *pgrp)
597 n = PGRP_HASH(pgrp->pg_id);
601 count = pgrp->pg_refs;
605 lwkt_gettoken(&prg->proc_token);
606 if (atomic_cmpset_int(&pgrp->pg_refs, 1, 0))
608 lwkt_reltoken(&prg->proc_token);
611 if (atomic_cmpset_int(&pgrp->pg_refs, count, count - 1))
618 * Successful 1->0 transition, pghash_spin is held.
620 LIST_REMOVE(pgrp, pg_list);
621 if (pid_doms[pgrp->pg_id % PIDSEL_DOMAINS] != (uint8_t)time_second)
622 pid_doms[pgrp->pg_id % PIDSEL_DOMAINS] = (uint8_t)time_second;
625 * Reset any sigio structures pointing to us as a result of
626 * F_SETOWN with our pgid.
628 funsetownlst(&pgrp->pg_sigiolst);
630 if (pgrp->pg_session->s_ttyp != NULL &&
631 pgrp->pg_session->s_ttyp->t_pgrp == pgrp) {
632 pgrp->pg_session->s_ttyp->t_pgrp = NULL;
634 lwkt_reltoken(&prg->proc_token);
636 sess_rele(pgrp->pg_session);
641 * Locate a process group by number. The returned process group will be
642 * referenced w/pgref() and must be released with pgrel() (or assigned
643 * somewhere if you wish to keep the reference).
656 lwkt_gettoken_shared(&prg->proc_token);
658 LIST_FOREACH(pgrp, &prg->allpgrp, pg_list) {
659 if (pgrp->pg_id == pgid) {
660 refcount_acquire(&pgrp->pg_refs);
661 lwkt_reltoken(&prg->proc_token);
665 lwkt_reltoken(&prg->proc_token);
670 * Move p to a new or existing process group (and session)
675 enterpgrp(struct proc *p, pid_t pgid, int mksess)
683 KASSERT(pgrp == NULL || !mksess,
684 ("enterpgrp: setsid into non-empty pgrp"));
685 KASSERT(!SESS_LEADER(p),
686 ("enterpgrp: session leader attempted setpgrp"));
689 pid_t savepid = p->p_pid;
697 KASSERT(p->p_pid == pgid,
698 ("enterpgrp: new pgrp and pid != pgid"));
699 pgrp = kmalloc(sizeof(struct pgrp), M_PGRP, M_WAITOK | M_ZERO);
701 LIST_INIT(&pgrp->pg_members);
703 SLIST_INIT(&pgrp->pg_sigiolst);
704 lwkt_token_init(&pgrp->pg_token, "pgrp_token");
705 refcount_init(&pgrp->pg_refs, 1);
706 lockinit(&pgrp->pg_lock, "pgwt", 0, 0);
711 if ((np = pfindn(savepid)) == NULL || np != p) {
712 lwkt_reltoken(&prg->proc_token);
718 lwkt_gettoken(&prg->proc_token);
720 struct session *sess;
725 sess = kmalloc(sizeof(struct session), M_SESSION,
727 lwkt_gettoken(&p->p_token);
730 sess->s_sid = p->p_pid;
732 sess->s_ttyvp = NULL;
734 bcopy(p->p_session->s_login, sess->s_login,
735 sizeof(sess->s_login));
736 pgrp->pg_session = sess;
737 KASSERT(p == curproc,
738 ("enterpgrp: mksession and p != curproc"));
739 p->p_flags &= ~P_CONTROLT;
740 LIST_INSERT_HEAD(&prg->allsess, sess, s_list);
741 lwkt_reltoken(&p->p_token);
743 lwkt_gettoken(&p->p_token);
744 pgrp->pg_session = p->p_session;
745 sess_hold(pgrp->pg_session);
746 lwkt_reltoken(&p->p_token);
748 LIST_INSERT_HEAD(&prg->allpgrp, pgrp, pg_list);
750 lwkt_reltoken(&prg->proc_token);
751 } else if (pgrp == p->p_pgrp) {
754 } /* else pgfind() referenced the pgrp */
756 lwkt_gettoken(&pgrp->pg_token);
757 lwkt_gettoken(&p->p_token);
760 * Replace p->p_pgrp, handling any races that occur.
762 while ((opgrp = p->p_pgrp) != NULL) {
764 lwkt_gettoken(&opgrp->pg_token);
765 if (opgrp != p->p_pgrp) {
766 lwkt_reltoken(&opgrp->pg_token);
770 LIST_REMOVE(p, p_pglist);
774 LIST_INSERT_HEAD(&pgrp->pg_members, p, p_pglist);
777 * Adjust eligibility of affected pgrps to participate in job control.
778 * Increment eligibility counts before decrementing, otherwise we
779 * could reach 0 spuriously during the first call.
783 fixjobc(p, opgrp, 0);
784 lwkt_reltoken(&opgrp->pg_token);
785 pgrel(opgrp); /* manual pgref */
786 pgrel(opgrp); /* p->p_pgrp ref */
788 lwkt_reltoken(&p->p_token);
789 lwkt_reltoken(&pgrp->pg_token);
797 * Remove process from process group
802 leavepgrp(struct proc *p)
804 struct pgrp *pg = p->p_pgrp;
806 lwkt_gettoken(&p->p_token);
807 while ((pg = p->p_pgrp) != NULL) {
809 lwkt_gettoken(&pg->pg_token);
810 if (p->p_pgrp != pg) {
811 lwkt_reltoken(&pg->pg_token);
816 LIST_REMOVE(p, p_pglist);
817 lwkt_reltoken(&pg->pg_token);
818 pgrel(pg); /* manual pgref */
819 pgrel(pg); /* p->p_pgrp ref */
822 lwkt_reltoken(&p->p_token);
828 * Adjust the ref count on a session structure. When the ref count falls to
829 * zero the tty is disassociated from the session and the session structure
830 * is freed. Note that tty assocation is not itself ref-counted.
835 sess_hold(struct session *sp)
837 atomic_add_int(&sp->s_count, 1);
844 sess_rele(struct session *sess)
851 n = SESS_HASH(sess->s_sid);
855 count = sess->s_count;
859 lwkt_gettoken(&prg->proc_token);
860 if (atomic_cmpset_int(&sess->s_count, 1, 0))
862 lwkt_reltoken(&prg->proc_token);
865 if (atomic_cmpset_int(&sess->s_count, count, count - 1))
872 * Successful 1->0 transition and prg->proc_token is held.
874 LIST_REMOVE(sess, s_list);
875 if (pid_doms[sess->s_sid % PIDSEL_DOMAINS] != (uint8_t)time_second)
876 pid_doms[sess->s_sid % PIDSEL_DOMAINS] = (uint8_t)time_second;
878 if (sess->s_ttyp && sess->s_ttyp->t_session) {
879 #ifdef TTY_DO_FULL_CLOSE
880 /* FULL CLOSE, see ttyclearsession() */
881 KKASSERT(sess->s_ttyp->t_session == sess);
882 sess->s_ttyp->t_session = NULL;
884 /* HALF CLOSE, see ttyclearsession() */
885 if (sess->s_ttyp->t_session == sess)
886 sess->s_ttyp->t_session = NULL;
889 if ((tp = sess->s_ttyp) != NULL) {
893 lwkt_reltoken(&prg->proc_token);
895 kfree(sess, M_SESSION);
899 * Adjust pgrp jobc counters when specified process changes process group.
900 * We count the number of processes in each process group that "qualify"
901 * the group for terminal job control (those with a parent in a different
902 * process group of the same session). If that count reaches zero, the
903 * process group becomes orphaned. Check both the specified process'
904 * process group and that of its children.
905 * entering == 0 => p is leaving specified group.
906 * entering == 1 => p is entering specified group.
911 fixjobc(struct proc *p, struct pgrp *pgrp, int entering)
913 struct pgrp *hispgrp;
914 struct session *mysession;
918 * Check p's parent to see whether p qualifies its own process
919 * group; if so, adjust count for p's process group.
921 lwkt_gettoken(&p->p_token); /* p_children scan */
922 lwkt_gettoken(&pgrp->pg_token);
924 mysession = pgrp->pg_session;
925 if ((hispgrp = p->p_pptr->p_pgrp) != pgrp &&
926 hispgrp->pg_session == mysession) {
929 else if (--pgrp->pg_jobc == 0)
934 * Check this process' children to see whether they qualify
935 * their process groups; if so, adjust counts for children's
938 LIST_FOREACH(np, &p->p_children, p_sibling) {
940 lwkt_gettoken(&np->p_token);
941 if ((hispgrp = np->p_pgrp) != pgrp &&
942 hispgrp->pg_session == mysession &&
943 np->p_stat != SZOMB) {
945 lwkt_gettoken(&hispgrp->pg_token);
948 else if (--hispgrp->pg_jobc == 0)
950 lwkt_reltoken(&hispgrp->pg_token);
953 lwkt_reltoken(&np->p_token);
956 KKASSERT(pgrp->pg_refs > 0);
957 lwkt_reltoken(&pgrp->pg_token);
958 lwkt_reltoken(&p->p_token);
962 * A process group has become orphaned;
963 * if there are any stopped processes in the group,
964 * hang-up all process in that group.
966 * The caller must hold pg_token.
969 orphanpg(struct pgrp *pg)
973 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
974 if (p->p_stat == SSTOP) {
975 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
985 * Add a new process to the allproc list and the PID hash. This
986 * also assigns a pid to the new process.
991 proc_add_allproc(struct proc *p)
995 if ((random_offset = randompid) != 0) {
996 read_random(&random_offset, sizeof(random_offset));
997 random_offset = (random_offset & 0x7FFFFFFF) % randompid;
999 proc_makepid(p, random_offset);
1003 * Calculate a new process pid. This function is integrated into
1004 * proc_add_allproc() to guarentee that the new pid is not reused before
1005 * the new process can be added to the allproc list.
1007 * p_pid is assigned and the process is added to the allproc hash table
1009 * WARNING! We need to allocate PIDs sequentially during early boot.
1010 * In particular, init needs to have a pid of 1.
1014 proc_makepid(struct proc *p, int random_offset)
1016 static pid_t nextpid = 1; /* heuristic, allowed to race */
1020 struct session *sess;
1027 * Select the next pid base candidate.
1029 * Check cyclement, do not allow a pid < 100.
1033 base = atomic_fetchadd_int(&nextpid, 1) + random_offset;
1034 if (base <= 0 || base >= PID_MAX) {
1035 base = base % PID_MAX;
1040 nextpid = base; /* reset (SMP race ok) */
1044 * Do not allow a base pid to be selected from a domain that has
1045 * recently seen a pid/pgid/sessid reap. Sleep a little if we looped
1046 * through all available domains.
1048 * WARNING: We want the early pids to be allocated linearly,
1049 * particularly pid 1 and pid 2.
1051 if (++retries >= PIDSEL_DOMAINS)
1052 tsleep(&nextpid, 0, "makepid", 1);
1054 delta8 = (int8_t)time_second -
1055 (int8_t)pid_doms[base % PIDSEL_DOMAINS];
1056 if (delta8 >= 0 && delta8 <= PIDDOM_DELAY) {
1063 * Calculate a hash index and find an unused process id within
1064 * the table, looping if we cannot find one.
1066 * The inner loop increments by ALLPROC_HSIZE which keeps the
1067 * PID at the same pid_doms[] index as well as the same hash index.
1069 n = ALLPROC_HASH(base);
1071 lwkt_gettoken(&prg->proc_token);
1074 LIST_FOREACH(ps, &prg->allproc, p_list) {
1075 if (ps->p_pid == base) {
1076 base += ALLPROC_HSIZE;
1077 if (base >= PID_MAX) {
1078 lwkt_reltoken(&prg->proc_token);
1085 LIST_FOREACH(pg, &prg->allpgrp, pg_list) {
1086 if (pg->pg_id == base) {
1087 base += ALLPROC_HSIZE;
1088 if (base >= PID_MAX) {
1089 lwkt_reltoken(&prg->proc_token);
1096 LIST_FOREACH(sess, &prg->allsess, s_list) {
1097 if (sess->s_sid == base) {
1098 base += ALLPROC_HSIZE;
1099 if (base >= PID_MAX) {
1100 lwkt_reltoken(&prg->proc_token);
1109 * Assign the pid and insert the process.
1112 LIST_INSERT_HEAD(&prg->allproc, p, p_list);
1113 lwkt_reltoken(&prg->proc_token);
1117 * Called from exit1 to place the process into a zombie state.
1118 * The process is removed from the pid hash and p_stat is set
1119 * to SZOMB. Normal pfind[n]() calls will not find it any more.
1121 * Caller must hold p->p_token. We are required to wait until p_lock
1122 * becomes zero before we can manipulate the list, allowing allproc
1123 * scans to guarantee consistency during a list scan.
1126 proc_move_allproc_zombie(struct proc *p)
1131 n = ALLPROC_HASH(p->p_pid);
1133 PSTALL(p, "reap1", 0);
1134 lwkt_gettoken(&prg->proc_token);
1136 PSTALL(p, "reap1a", 0);
1139 lwkt_reltoken(&prg->proc_token);
1140 dsched_exit_proc(p);
1144 * This routine is called from kern_wait() and will remove the process
1145 * from the zombie list and the sibling list. This routine will block
1146 * if someone has a lock on the proces (p_lock).
1148 * Caller must hold p->p_token. We are required to wait until p_lock
1149 * becomes one before we can manipulate the list, allowing allproc
1150 * scans to guarantee consistency during a list scan.
1152 * Assumes caller has one ref.
1155 proc_remove_zombie(struct proc *p)
1160 n = ALLPROC_HASH(p->p_pid);
1163 PSTALL(p, "reap2", 1);
1164 lwkt_gettoken(&prg->proc_token);
1165 PSTALL(p, "reap2a", 1);
1166 LIST_REMOVE(p, p_list); /* from remove master list */
1167 LIST_REMOVE(p, p_sibling); /* and from sibling list */
1170 if (pid_doms[p->p_pid % PIDSEL_DOMAINS] != (uint8_t)time_second)
1171 pid_doms[p->p_pid % PIDSEL_DOMAINS] = (uint8_t)time_second;
1172 lwkt_reltoken(&prg->proc_token);
1176 * Handle various requirements prior to returning to usermode. Called from
1177 * platform trap and system call code.
1180 lwpuserret(struct lwp *lp)
1182 struct proc *p = lp->lwp_proc;
1184 if (lp->lwp_mpflags & LWP_MP_VNLRU) {
1185 atomic_clear_int(&lp->lwp_mpflags, LWP_MP_VNLRU);
1188 if (lp->lwp_mpflags & LWP_MP_WEXIT) {
1189 lwkt_gettoken(&p->p_token);
1191 lwkt_reltoken(&p->p_token); /* NOT REACHED */
1196 * Kernel threads run from user processes can also accumulate deferred
1197 * actions which need to be acted upon. Callers include:
1199 * nfsd - Can allocate lots of vnodes
1202 lwpkthreaddeferred(void)
1204 struct lwp *lp = curthread->td_lwp;
1207 if (lp->lwp_mpflags & LWP_MP_VNLRU) {
1208 atomic_clear_int(&lp->lwp_mpflags, LWP_MP_VNLRU);
1215 proc_usermap(struct proc *p, int invfork)
1217 struct sys_upmap *upmap;
1219 lwkt_gettoken(&p->p_token);
1220 upmap = kmalloc(roundup2(sizeof(*upmap), PAGE_SIZE), M_PROC,
1222 if (p->p_upmap == NULL) {
1223 upmap->header[0].type = UKPTYPE_VERSION;
1224 upmap->header[0].offset = offsetof(struct sys_upmap, version);
1225 upmap->header[1].type = UPTYPE_RUNTICKS;
1226 upmap->header[1].offset = offsetof(struct sys_upmap, runticks);
1227 upmap->header[2].type = UPTYPE_FORKID;
1228 upmap->header[2].offset = offsetof(struct sys_upmap, forkid);
1229 upmap->header[3].type = UPTYPE_PID;
1230 upmap->header[3].offset = offsetof(struct sys_upmap, pid);
1231 upmap->header[4].type = UPTYPE_PROC_TITLE;
1232 upmap->header[4].offset = offsetof(struct sys_upmap,proc_title);
1233 upmap->header[5].type = UPTYPE_INVFORK;
1234 upmap->header[5].offset = offsetof(struct sys_upmap, invfork);
1236 upmap->version = UPMAP_VERSION;
1237 upmap->pid = p->p_pid;
1238 upmap->forkid = p->p_forkid;
1239 upmap->invfork = invfork;
1242 kfree(upmap, M_PROC);
1244 lwkt_reltoken(&p->p_token);
1248 proc_userunmap(struct proc *p)
1250 struct sys_upmap *upmap;
1252 lwkt_gettoken(&p->p_token);
1253 if ((upmap = p->p_upmap) != NULL) {
1255 kfree(upmap, M_PROC);
1257 lwkt_reltoken(&p->p_token);
1261 * Scan all processes on the allproc list. The process is automatically
1262 * held for the callback. A return value of -1 terminates the loop.
1263 * Zombie procs are skipped.
1265 * The callback is made with the process held and proc_token held.
1267 * We limit the scan to the number of processes as-of the start of
1268 * the scan so as not to get caught up in an endless loop if new processes
1269 * are created more quickly than we can scan the old ones. Add a little
1270 * slop to try to catch edge cases since nprocs can race.
1275 allproc_scan(int (*callback)(struct proc *, void *), void *data, int segmented)
1277 int limit = nprocs + ncpus;
1285 int id = mycpu->gd_cpuid;
1286 ns = id * ALLPROC_HSIZE / ncpus;
1287 ne = (id + 1) * ALLPROC_HSIZE / ncpus;
1294 * prg->proc_token protects the allproc list and PHOLD() prevents the
1295 * process from being removed from the allproc list or the zombproc
1298 for (n = ns; n < ne; ++n) {
1299 procglob_t *prg = &procglob[n];
1300 if (LIST_FIRST(&prg->allproc) == NULL)
1302 lwkt_gettoken(&prg->proc_token);
1303 LIST_FOREACH(p, &prg->allproc, p_list) {
1304 if (p->p_stat == SZOMB)
1307 r = callback(p, data);
1314 lwkt_reltoken(&prg->proc_token);
1317 * Check if asked to stop early
1325 * Scan all lwps of processes on the allproc list. The lwp is automatically
1326 * held for the callback. A return value of -1 terminates the loop.
1328 * The callback is made with the proces and lwp both held, and proc_token held.
1333 alllwp_scan(int (*callback)(struct lwp *, void *), void *data, int segmented)
1343 int id = mycpu->gd_cpuid;
1344 ns = id * ALLPROC_HSIZE / ncpus;
1345 ne = (id + 1) * ALLPROC_HSIZE / ncpus;
1351 for (n = ns; n < ne; ++n) {
1352 procglob_t *prg = &procglob[n];
1354 if (LIST_FIRST(&prg->allproc) == NULL)
1356 lwkt_gettoken(&prg->proc_token);
1357 LIST_FOREACH(p, &prg->allproc, p_list) {
1358 if (p->p_stat == SZOMB)
1361 lwkt_gettoken(&p->p_token);
1362 FOREACH_LWP_IN_PROC(lp, p) {
1364 r = callback(lp, data);
1367 lwkt_reltoken(&p->p_token);
1372 lwkt_reltoken(&prg->proc_token);
1375 * Asked to exit early
1383 * Scan all processes on the zombproc list. The process is automatically
1384 * held for the callback. A return value of -1 terminates the loop.
1387 * The callback is made with the proces held and proc_token held.
1390 zombproc_scan(int (*callback)(struct proc *, void *), void *data)
1397 * prg->proc_token protects the allproc list and PHOLD() prevents the
1398 * process from being removed from the allproc list or the zombproc
1401 for (n = 0; n < ALLPROC_HSIZE; ++n) {
1402 procglob_t *prg = &procglob[n];
1404 if (LIST_FIRST(&prg->allproc) == NULL)
1406 lwkt_gettoken(&prg->proc_token);
1407 LIST_FOREACH(p, &prg->allproc, p_list) {
1408 if (p->p_stat != SZOMB)
1411 r = callback(p, data);
1416 lwkt_reltoken(&prg->proc_token);
1419 * Check if asked to stop early
1426 #include "opt_ddb.h"
1428 #include <ddb/ddb.h>
1433 DB_SHOW_COMMAND(pgrpdump, pgrpdump)
1440 for (i = 0; i < ALLPROC_HSIZE; ++i) {
1443 if (LIST_EMPTY(&prg->allpgrp))
1445 kprintf("\tindx %d\n", i);
1446 LIST_FOREACH(pgrp, &prg->allpgrp, pg_list) {
1447 kprintf("\tpgrp %p, pgid %ld, sess %p, "
1448 "sesscnt %d, mem %p\n",
1449 (void *)pgrp, (long)pgrp->pg_id,
1450 (void *)pgrp->pg_session,
1451 pgrp->pg_session->s_count,
1452 (void *)LIST_FIRST(&pgrp->pg_members));
1453 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
1454 kprintf("\t\tpid %ld addr %p pgrp %p\n",
1455 (long)p->p_pid, (void *)p,
1464 * The caller must hold proc_token.
1467 sysctl_out_proc(struct proc *p, struct sysctl_req *req, int flags)
1469 struct kinfo_proc ki;
1471 int skp = 0, had_output = 0;
1474 bzero(&ki, sizeof(ki));
1475 lwkt_gettoken_shared(&p->p_token);
1476 fill_kinfo_proc(p, &ki);
1477 if ((flags & KERN_PROC_FLAG_LWP) == 0)
1480 FOREACH_LWP_IN_PROC(lp, p) {
1482 fill_kinfo_lwp(lp, &ki.kp_lwp);
1484 error = SYSCTL_OUT(req, &ki, sizeof(ki));
1491 lwkt_reltoken(&p->p_token);
1492 /* We need to output at least the proc, even if there is no lwp. */
1493 if (had_output == 0) {
1494 error = SYSCTL_OUT(req, &ki, sizeof(ki));
1500 * The caller must hold proc_token.
1503 sysctl_out_proc_kthread(struct thread *td, struct sysctl_req *req)
1505 struct kinfo_proc ki;
1508 fill_kinfo_proc_kthread(td, &ki);
1509 error = SYSCTL_OUT(req, &ki, sizeof(ki));
1519 sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
1521 int *name = (int *)arg1;
1522 int oid = oidp->oid_number;
1523 u_int namelen = arg2;
1526 struct thread *marker;
1531 struct ucred *cr1 = curproc->p_ucred;
1532 struct ucred *crcache = NULL;
1534 flags = oid & KERN_PROC_FLAGMASK;
1535 oid &= ~KERN_PROC_FLAGMASK;
1537 if ((oid == KERN_PROC_ALL && namelen != 0) ||
1538 (oid != KERN_PROC_ALL && namelen != 1)) {
1543 * proc_token protects the allproc list and PHOLD() prevents the
1544 * process from being removed from the allproc list or the zombproc
1547 if (oid == KERN_PROC_PID) {
1548 p = pfind((pid_t)name[0]);
1550 crcache = pcredcache(crcache, p);
1551 if (PRISON_CHECK(cr1, crcache))
1552 error = sysctl_out_proc(p, req, flags);
1560 /* overestimate by 5 procs */
1561 error = SYSCTL_OUT(req, 0, sizeof (struct kinfo_proc) * 5);
1566 for (n = 0; n < ALLPROC_HSIZE; ++n) {
1567 procglob_t *prg = &procglob[n];
1569 if (LIST_EMPTY(&prg->allproc))
1571 lwkt_gettoken_shared(&prg->proc_token);
1572 LIST_FOREACH(p, &prg->allproc, p_list) {
1574 * Show a user only their processes.
1576 if (ps_showallprocs == 0) {
1577 crcache = pcredcache(crcache, p);
1578 if (crcache == NULL ||
1579 p_trespass(cr1, crcache)) {
1585 * Skip embryonic processes.
1587 if (p->p_stat == SIDL)
1590 * TODO - make more efficient (see notes below).
1594 case KERN_PROC_PGRP:
1595 /* could do this by traversing pgrp */
1596 if (p->p_pgrp == NULL ||
1597 p->p_pgrp->pg_id != (pid_t)name[0])
1602 if ((p->p_flags & P_CONTROLT) == 0 ||
1603 p->p_session == NULL ||
1604 p->p_session->s_ttyp == NULL ||
1605 dev2udev(p->p_session->s_ttyp->t_dev) !=
1611 crcache = pcredcache(crcache, p);
1612 if (crcache == NULL ||
1613 crcache->cr_uid != (uid_t)name[0]) {
1618 case KERN_PROC_RUID:
1619 crcache = pcredcache(crcache, p);
1620 if (crcache == NULL ||
1621 crcache->cr_ruid != (uid_t)name[0]) {
1627 crcache = pcredcache(crcache, p);
1628 if (!PRISON_CHECK(cr1, crcache))
1631 error = sysctl_out_proc(p, req, flags);
1634 lwkt_reltoken(&prg->proc_token);
1638 lwkt_reltoken(&prg->proc_token);
1642 * Iterate over all active cpus and scan their thread list. Start
1643 * with the next logical cpu and end with our original cpu. We
1644 * migrate our own thread to each target cpu in order to safely scan
1645 * its thread list. In the last loop we migrate back to our original
1648 origcpu = mycpu->gd_cpuid;
1649 if (!ps_showallthreads || jailed(cr1))
1652 marker = kmalloc(sizeof(struct thread), M_TEMP, M_WAITOK|M_ZERO);
1653 marker->td_flags = TDF_MARKER;
1656 for (n = 1; n <= ncpus; ++n) {
1660 nid = (origcpu + n) % ncpus;
1661 if (CPUMASK_TESTBIT(smp_active_mask, nid) == 0)
1663 rgd = globaldata_find(nid);
1664 lwkt_setcpu_self(rgd);
1667 TAILQ_INSERT_TAIL(&rgd->gd_tdallq, marker, td_allq);
1669 while ((td = TAILQ_PREV(marker, lwkt_queue, td_allq)) != NULL) {
1670 TAILQ_REMOVE(&rgd->gd_tdallq, marker, td_allq);
1671 TAILQ_INSERT_BEFORE(td, marker, td_allq);
1672 if (td->td_flags & TDF_MARKER)
1681 case KERN_PROC_PGRP:
1684 case KERN_PROC_RUID:
1687 error = sysctl_out_proc_kthread(td, req);
1695 TAILQ_REMOVE(&rgd->gd_tdallq, marker, td_allq);
1703 * Userland scheduler expects us to return on the same cpu we
1706 if (mycpu->gd_cpuid != origcpu)
1707 lwkt_setcpu_self(globaldata_find(origcpu));
1709 kfree(marker, M_TEMP);
1718 * This sysctl allows a process to retrieve the argument list or process
1719 * title for another process without groping around in the address space
1720 * of the other process. It also allow a process to set its own "process
1721 * title to a string of its own choice.
1726 sysctl_kern_proc_args(SYSCTL_HANDLER_ARGS)
1728 int *name = (int*) arg1;
1729 u_int namelen = arg2;
1734 struct ucred *cr1 = curproc->p_ucred;
1739 p = pfind((pid_t)name[0]);
1742 lwkt_gettoken(&p->p_token);
1744 if ((!ps_argsopen) && p_trespass(cr1, p->p_ucred))
1747 if (req->newptr && curproc != p) {
1752 if (p->p_upmap != NULL && p->p_upmap->proc_title[0]) {
1754 * Args set via writable user process mmap.
1755 * We must calculate the string length manually
1756 * because the user data can change at any time.
1761 base = p->p_upmap->proc_title;
1762 for (n = 0; n < UPMAP_MAXPROCTITLE - 1; ++n) {
1766 error = SYSCTL_OUT(req, base, n);
1768 error = SYSCTL_OUT(req, "", 1);
1769 } else if ((pa = p->p_args) != NULL) {
1771 * Args set by setproctitle() sysctl.
1773 refcount_acquire(&pa->ar_ref);
1774 error = SYSCTL_OUT(req, pa->ar_args, pa->ar_length);
1775 if (refcount_release(&pa->ar_ref))
1779 if (req->newptr == NULL)
1782 if (req->newlen + sizeof(struct pargs) > ps_arg_cache_limit) {
1786 pa = kmalloc(sizeof(struct pargs) + req->newlen, M_PARGS, M_WAITOK);
1787 refcount_init(&pa->ar_ref, 1);
1788 pa->ar_length = req->newlen;
1789 error = SYSCTL_IN(req, pa->ar_args, req->newlen);
1797 * Replace p_args with the new pa. p_args may have previously
1804 KKASSERT(opa->ar_ref > 0);
1805 if (refcount_release(&opa->ar_ref)) {
1806 kfree(opa, M_PARGS);
1812 lwkt_reltoken(&p->p_token);
1819 sysctl_kern_proc_cwd(SYSCTL_HANDLER_ARGS)
1821 int *name = (int*) arg1;
1822 u_int namelen = arg2;
1825 char *fullpath, *freepath;
1826 struct ucred *cr1 = curproc->p_ucred;
1831 p = pfind((pid_t)name[0]);
1834 lwkt_gettoken_shared(&p->p_token);
1837 * If we are not allowed to see other args, we certainly shouldn't
1838 * get the cwd either. Also check the usual trespassing.
1840 if ((!ps_argsopen) && p_trespass(cr1, p->p_ucred))
1843 if (req->oldptr && p->p_fd != NULL && p->p_fd->fd_ncdir.ncp) {
1844 struct nchandle nch;
1846 cache_copy(&p->p_fd->fd_ncdir, &nch);
1847 error = cache_fullpath(p, &nch, NULL,
1848 &fullpath, &freepath, 0);
1852 error = SYSCTL_OUT(req, fullpath, strlen(fullpath) + 1);
1853 kfree(freepath, M_TEMP);
1858 lwkt_reltoken(&p->p_token);
1865 * This sysctl allows a process to retrieve the path of the executable for
1866 * itself or another process.
1869 sysctl_kern_proc_pathname(SYSCTL_HANDLER_ARGS)
1871 pid_t *pidp = (pid_t *)arg1;
1872 unsigned int arglen = arg2;
1874 char *retbuf, *freebuf;
1876 struct nchandle nch;
1880 if (*pidp == -1) { /* -1 means this process */
1888 cache_copy(&p->p_textnch, &nch);
1889 error = cache_fullpath(p, &nch, NULL, &retbuf, &freebuf, 0);
1893 error = SYSCTL_OUT(req, retbuf, strlen(retbuf) + 1);
1894 kfree(freebuf, M_TEMP);
1903 sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS)
1905 /*int *name = (int *)arg1;*/
1906 u_int namelen = arg2;
1907 struct kinfo_sigtramp kst;
1908 const struct sysentvec *sv;
1913 /* ignore pid if passed in (freebsd compatibility) */
1915 sv = curproc->p_sysent;
1916 bzero(&kst, sizeof(kst));
1917 if (sv->sv_szsigcode) {
1920 sigbase = trunc_page64((intptr_t)PS_STRINGS -
1922 sigbase -= SZSIGCODE_EXTRA_BYTES;
1924 kst.ksigtramp_start = (void *)sigbase;
1925 kst.ksigtramp_end = (void *)(sigbase + *sv->sv_szsigcode);
1927 error = SYSCTL_OUT(req, &kst, sizeof(kst));
1932 SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD, 0, "Process table");
1934 SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all,
1935 CTLFLAG_RD | CTLTYPE_STRUCT | CTLFLAG_NOLOCK,
1936 0, 0, sysctl_kern_proc, "S,proc", "Return entire process table");
1938 SYSCTL_NODE(_kern_proc, KERN_PROC_PGRP, pgrp,
1939 CTLFLAG_RD | CTLFLAG_NOLOCK,
1940 sysctl_kern_proc, "Process table");
1942 SYSCTL_NODE(_kern_proc, KERN_PROC_TTY, tty,
1943 CTLFLAG_RD | CTLFLAG_NOLOCK,
1944 sysctl_kern_proc, "Process table");
1946 SYSCTL_NODE(_kern_proc, KERN_PROC_UID, uid,
1947 CTLFLAG_RD | CTLFLAG_NOLOCK,
1948 sysctl_kern_proc, "Process table");
1950 SYSCTL_NODE(_kern_proc, KERN_PROC_RUID, ruid,
1951 CTLFLAG_RD | CTLFLAG_NOLOCK,
1952 sysctl_kern_proc, "Process table");
1954 SYSCTL_NODE(_kern_proc, KERN_PROC_PID, pid,
1955 CTLFLAG_RD | CTLFLAG_NOLOCK,
1956 sysctl_kern_proc, "Process table");
1958 SYSCTL_NODE(_kern_proc, (KERN_PROC_ALL | KERN_PROC_FLAG_LWP), all_lwp,
1959 CTLFLAG_RD | CTLFLAG_NOLOCK,
1960 sysctl_kern_proc, "Process table");
1962 SYSCTL_NODE(_kern_proc, (KERN_PROC_PGRP | KERN_PROC_FLAG_LWP), pgrp_lwp,
1963 CTLFLAG_RD | CTLFLAG_NOLOCK,
1964 sysctl_kern_proc, "Process table");
1966 SYSCTL_NODE(_kern_proc, (KERN_PROC_TTY | KERN_PROC_FLAG_LWP), tty_lwp,
1967 CTLFLAG_RD | CTLFLAG_NOLOCK,
1968 sysctl_kern_proc, "Process table");
1970 SYSCTL_NODE(_kern_proc, (KERN_PROC_UID | KERN_PROC_FLAG_LWP), uid_lwp,
1971 CTLFLAG_RD | CTLFLAG_NOLOCK,
1972 sysctl_kern_proc, "Process table");
1974 SYSCTL_NODE(_kern_proc, (KERN_PROC_RUID | KERN_PROC_FLAG_LWP), ruid_lwp,
1975 CTLFLAG_RD | CTLFLAG_NOLOCK,
1976 sysctl_kern_proc, "Process table");
1978 SYSCTL_NODE(_kern_proc, (KERN_PROC_PID | KERN_PROC_FLAG_LWP), pid_lwp,
1979 CTLFLAG_RD | CTLFLAG_NOLOCK,
1980 sysctl_kern_proc, "Process table");
1982 SYSCTL_NODE(_kern_proc, KERN_PROC_ARGS, args,
1983 CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_NOLOCK,
1984 sysctl_kern_proc_args, "Process argument list");
1986 SYSCTL_NODE(_kern_proc, KERN_PROC_CWD, cwd,
1987 CTLFLAG_RD | CTLFLAG_ANYBODY | CTLFLAG_NOLOCK,
1988 sysctl_kern_proc_cwd, "Process argument list");
1990 static SYSCTL_NODE(_kern_proc, KERN_PROC_PATHNAME, pathname,
1991 CTLFLAG_RD | CTLFLAG_NOLOCK,
1992 sysctl_kern_proc_pathname, "Process executable path");
1994 SYSCTL_PROC(_kern_proc, KERN_PROC_SIGTRAMP, sigtramp,
1995 CTLFLAG_RD | CTLTYPE_STRUCT | CTLFLAG_NOLOCK,
1996 0, 0, sysctl_kern_proc_sigtramp, "S,sigtramp",
1997 "Return sigtramp address range");