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;
148 sysctl_kern_randompid(SYSCTL_HANDLER_ARGS
)
153 error
= sysctl_handle_int(oidp
, &pid
, 0, req
);
154 if (error
|| !req
->newptr
)
156 if (pid
< 0 || pid
> PID_MAX
- 100) /* out of range */
158 else if (pid
< 2) /* NOP */
160 else if (pid
< 100) /* Make it reasonable */
166 SYSCTL_PROC(_kern
, OID_AUTO
, randompid
, CTLTYPE_INT
|CTLFLAG_RW
,
167 0, 0, sysctl_kern_randompid
, "I", "Random PID modulus");
170 * Initialize global process hashing structures.
172 * These functions are ONLY called from the low level boot code and do
173 * not lock their operations.
181 * Allocate dynamically. This array can be large (~1MB) so don't
182 * waste boot loader space.
184 pid_doms
= kmalloc(sizeof(pid_doms
[0]) * PIDSEL_DOMAINS
,
185 M_PROC
, M_WAITOK
| M_ZERO
);
188 * Avoid unnecessary stalls due to pid_doms[] values all being
189 * the same. Make sure that the allocation of pid 1 and pid 2
192 for (i
= 0; i
< PIDSEL_DOMAINS
; ++i
)
193 pid_doms
[i
] = (int8_t)i
- (int8_t)(PIDDOM_DELAY
+ 1);
198 for (i
= 0; i
< ALLPROC_HSIZE
; ++i
) {
199 procglob_t
*prg
= &procglob
[i
];
200 LIST_INIT(&prg
->allproc
);
201 LIST_INIT(&prg
->allsess
);
202 LIST_INIT(&prg
->allpgrp
);
203 lwkt_token_init(&prg
->proc_token
, "allproc");
209 procinsertinit(struct proc
*p
)
211 LIST_INSERT_HEAD(&procglob
[ALLPROC_HASH(p
->p_pid
)].allproc
,
216 pgrpinsertinit(struct pgrp
*pg
)
218 LIST_INSERT_HEAD(&procglob
[ALLPROC_HASH(pg
->pg_id
)].allpgrp
,
223 sessinsertinit(struct session
*sess
)
225 LIST_INSERT_HEAD(&procglob
[ALLPROC_HASH(sess
->s_sid
)].allsess
,
230 * Process hold/release support functions. Called via the PHOLD(),
231 * PRELE(), and PSTALL() macros.
233 * p->p_lock is a simple hold count with a waiting interlock. No wakeup()
234 * is issued unless someone is actually waiting for the process.
236 * Most holds are short-term, allowing a process scan or other similar
237 * operation to access a proc structure without it getting ripped out from
238 * under us. procfs and process-list sysctl ops also use the hold function
239 * interlocked with various p_flags to keep the vmspace intact when reading
240 * or writing a user process's address space.
242 * There are two situations where a hold count can be longer. Exiting lwps
243 * hold the process until the lwp is reaped, and the parent will hold the
244 * child during vfork()/exec() sequences while the child is marked P_PPWAIT.
246 * The kernel waits for the hold count to drop to 0 (or 1 in some cases) at
247 * various critical points in the fork/exec and exit paths before proceeding.
249 #define PLOCK_ZOMB 0x20000000
250 #define PLOCK_WAITING 0x40000000
251 #define PLOCK_MASK 0x1FFFFFFF
254 pstall(struct proc
*p
, const char *wmesg
, int count
)
262 if ((o
& PLOCK_MASK
) <= count
)
264 n
= o
| PLOCK_WAITING
;
265 tsleep_interlock(&p
->p_lock
, 0);
268 * If someone is trying to single-step the process during
269 * an exec or an exit they can deadlock us because procfs
270 * sleeps with the process held.
273 if (p
->p_flags
& P_INEXEC
) {
275 } else if (p
->p_flags
& P_POSTEXIT
) {
276 spin_lock(&p
->p_spin
);
279 spin_unlock(&p
->p_spin
);
284 if (atomic_cmpset_int(&p
->p_lock
, o
, n
)) {
285 tsleep(&p
->p_lock
, PINTERLOCKED
, wmesg
, 0);
291 phold(struct proc
*p
)
293 atomic_add_int(&p
->p_lock
, 1);
297 * WARNING! On last release (p) can become instantly invalid due to
301 prele(struct proc
*p
)
309 if (atomic_cmpset_int(&p
->p_lock
, 1, 0))
317 KKASSERT((o
& PLOCK_MASK
) > 0);
319 n
= (o
- 1) & ~PLOCK_WAITING
;
320 if (atomic_cmpset_int(&p
->p_lock
, o
, n
)) {
321 if (o
& PLOCK_WAITING
)
329 * Hold and flag serialized for zombie reaping purposes.
331 * This function will fail if it has to block, returning non-zero with
332 * neither the flag set or the hold count bumped. Note that we must block
333 * without holding a ref, meaning that the caller must ensure that (p)
334 * remains valid through some other interlock (typically on its parent
335 * process's p_token).
337 * Zero is returned on success. The hold count will be incremented and
338 * the serialization flag acquired. Note that serialization is only against
339 * other pholdzomb() calls, not against phold() calls.
342 pholdzomb(struct proc
*p
)
350 if (atomic_cmpset_int(&p
->p_lock
, 0, PLOCK_ZOMB
| 1))
359 if ((o
& PLOCK_ZOMB
) == 0) {
360 n
= (o
+ 1) | PLOCK_ZOMB
;
361 if (atomic_cmpset_int(&p
->p_lock
, o
, n
))
364 KKASSERT((o
& PLOCK_MASK
) > 0);
365 n
= o
| PLOCK_WAITING
;
366 tsleep_interlock(&p
->p_lock
, 0);
367 if (atomic_cmpset_int(&p
->p_lock
, o
, n
)) {
368 tsleep(&p
->p_lock
, PINTERLOCKED
, "phldz", 0);
369 /* (p) can be ripped out at this point */
377 * Release PLOCK_ZOMB and the hold count, waking up any waiters.
379 * WARNING! On last release (p) can become instantly invalid due to
383 prelezomb(struct proc
*p
)
391 if (atomic_cmpset_int(&p
->p_lock
, PLOCK_ZOMB
| 1, 0))
397 KKASSERT(p
->p_lock
& PLOCK_ZOMB
);
400 KKASSERT((o
& PLOCK_MASK
) > 0);
402 n
= (o
- 1) & ~(PLOCK_ZOMB
| PLOCK_WAITING
);
403 if (atomic_cmpset_int(&p
->p_lock
, o
, n
)) {
404 if (o
& PLOCK_WAITING
)
412 * Is p an inferior of the current process?
417 inferior(struct proc
*p
)
422 lwkt_gettoken_shared(&p
->p_token
);
423 while (p
!= curproc
) {
425 lwkt_reltoken(&p
->p_token
);
430 lwkt_reltoken(&p
->p_token
);
432 lwkt_gettoken_shared(&p2
->p_token
);
435 lwkt_reltoken(&p
->p_token
);
442 * Locate a process by number. The returned process will be referenced and
443 * must be released with PRELE().
450 struct proc
*p
= curproc
;
455 * Shortcut the current process
457 if (p
&& p
->p_pid
== pid
) {
463 * Otherwise find it in the hash table.
465 n
= ALLPROC_HASH(pid
);
468 lwkt_gettoken_shared(&prg
->proc_token
);
469 LIST_FOREACH(p
, &prg
->allproc
, p_list
) {
470 if (p
->p_stat
== SZOMB
)
472 if (p
->p_pid
== pid
) {
474 lwkt_reltoken(&prg
->proc_token
);
478 lwkt_reltoken(&prg
->proc_token
);
484 * Locate a process by number. The returned process is NOT referenced.
485 * The result will not be stable and is typically only used to validate
486 * against a process that the caller has in-hand.
493 struct proc
*p
= curproc
;
498 * Shortcut the current process
500 if (p
&& p
->p_pid
== pid
)
504 * Otherwise find it in the hash table.
506 n
= ALLPROC_HASH(pid
);
509 lwkt_gettoken_shared(&prg
->proc_token
);
510 LIST_FOREACH(p
, &prg
->allproc
, p_list
) {
511 if (p
->p_stat
== SZOMB
)
513 if (p
->p_pid
== pid
) {
514 lwkt_reltoken(&prg
->proc_token
);
518 lwkt_reltoken(&prg
->proc_token
);
524 * Locate a process on the zombie list. Return a process or NULL.
525 * The returned process will be referenced and the caller must release
528 * No other requirements.
533 struct proc
*p
= curproc
;
538 * Shortcut the current process
540 if (p
&& p
->p_pid
== pid
) {
546 * Otherwise find it in the hash table.
548 n
= ALLPROC_HASH(pid
);
551 lwkt_gettoken_shared(&prg
->proc_token
);
552 LIST_FOREACH(p
, &prg
->allproc
, p_list
) {
553 if (p
->p_stat
!= SZOMB
)
555 if (p
->p_pid
== pid
) {
557 lwkt_reltoken(&prg
->proc_token
);
561 lwkt_reltoken(&prg
->proc_token
);
568 pgref(struct pgrp
*pgrp
)
570 refcount_acquire(&pgrp
->pg_refs
);
574 pgrel(struct pgrp
*pgrp
)
580 n
= PGRP_HASH(pgrp
->pg_id
);
584 count
= pgrp
->pg_refs
;
588 lwkt_gettoken(&prg
->proc_token
);
589 if (atomic_cmpset_int(&pgrp
->pg_refs
, 1, 0))
591 lwkt_reltoken(&prg
->proc_token
);
594 if (atomic_cmpset_int(&pgrp
->pg_refs
, count
, count
- 1))
601 * Successful 1->0 transition, pghash_spin is held.
603 LIST_REMOVE(pgrp
, pg_list
);
604 if (pid_doms
[pgrp
->pg_id
% PIDSEL_DOMAINS
] != (uint8_t)time_second
)
605 pid_doms
[pgrp
->pg_id
% PIDSEL_DOMAINS
] = (uint8_t)time_second
;
608 * Reset any sigio structures pointing to us as a result of
609 * F_SETOWN with our pgid.
611 funsetownlst(&pgrp
->pg_sigiolst
);
613 if (pgrp
->pg_session
->s_ttyp
!= NULL
&&
614 pgrp
->pg_session
->s_ttyp
->t_pgrp
== pgrp
) {
615 pgrp
->pg_session
->s_ttyp
->t_pgrp
= NULL
;
617 lwkt_reltoken(&prg
->proc_token
);
619 sess_rele(pgrp
->pg_session
);
624 * Locate a process group by number. The returned process group will be
625 * referenced w/pgref() and must be released with pgrel() (or assigned
626 * somewhere if you wish to keep the reference).
639 lwkt_gettoken_shared(&prg
->proc_token
);
641 LIST_FOREACH(pgrp
, &prg
->allpgrp
, pg_list
) {
642 if (pgrp
->pg_id
== pgid
) {
643 refcount_acquire(&pgrp
->pg_refs
);
644 lwkt_reltoken(&prg
->proc_token
);
648 lwkt_reltoken(&prg
->proc_token
);
653 * Move p to a new or existing process group (and session)
658 enterpgrp(struct proc
*p
, pid_t pgid
, int mksess
)
666 KASSERT(pgrp
== NULL
|| !mksess
,
667 ("enterpgrp: setsid into non-empty pgrp"));
668 KASSERT(!SESS_LEADER(p
),
669 ("enterpgrp: session leader attempted setpgrp"));
672 pid_t savepid
= p
->p_pid
;
680 KASSERT(p
->p_pid
== pgid
,
681 ("enterpgrp: new pgrp and pid != pgid"));
682 pgrp
= kmalloc(sizeof(struct pgrp
), M_PGRP
, M_WAITOK
| M_ZERO
);
684 LIST_INIT(&pgrp
->pg_members
);
686 SLIST_INIT(&pgrp
->pg_sigiolst
);
687 lwkt_token_init(&pgrp
->pg_token
, "pgrp_token");
688 refcount_init(&pgrp
->pg_refs
, 1);
689 lockinit(&pgrp
->pg_lock
, "pgwt", 0, 0);
694 if ((np
= pfindn(savepid
)) == NULL
|| np
!= p
) {
695 lwkt_reltoken(&prg
->proc_token
);
701 lwkt_gettoken(&prg
->proc_token
);
703 struct session
*sess
;
708 sess
= kmalloc(sizeof(struct session
), M_SESSION
,
710 lwkt_gettoken(&p
->p_token
);
712 sess
->s_sid
= p
->p_pid
;
714 sess
->s_ttyvp
= NULL
;
716 bcopy(p
->p_session
->s_login
, sess
->s_login
,
717 sizeof(sess
->s_login
));
718 pgrp
->pg_session
= sess
;
719 KASSERT(p
== curproc
,
720 ("enterpgrp: mksession and p != curproc"));
721 p
->p_flags
&= ~P_CONTROLT
;
722 LIST_INSERT_HEAD(&prg
->allsess
, sess
, s_list
);
723 lwkt_reltoken(&p
->p_token
);
725 lwkt_gettoken(&p
->p_token
);
726 pgrp
->pg_session
= p
->p_session
;
727 sess_hold(pgrp
->pg_session
);
728 lwkt_reltoken(&p
->p_token
);
730 LIST_INSERT_HEAD(&prg
->allpgrp
, pgrp
, pg_list
);
732 lwkt_reltoken(&prg
->proc_token
);
733 } else if (pgrp
== p
->p_pgrp
) {
736 } /* else pgfind() referenced the pgrp */
738 lwkt_gettoken(&pgrp
->pg_token
);
739 lwkt_gettoken(&p
->p_token
);
742 * Replace p->p_pgrp, handling any races that occur.
744 while ((opgrp
= p
->p_pgrp
) != NULL
) {
746 lwkt_gettoken(&opgrp
->pg_token
);
747 if (opgrp
!= p
->p_pgrp
) {
748 lwkt_reltoken(&opgrp
->pg_token
);
752 LIST_REMOVE(p
, p_pglist
);
756 LIST_INSERT_HEAD(&pgrp
->pg_members
, p
, p_pglist
);
759 * Adjust eligibility of affected pgrps to participate in job control.
760 * Increment eligibility counts before decrementing, otherwise we
761 * could reach 0 spuriously during the first call.
765 fixjobc(p
, opgrp
, 0);
766 lwkt_reltoken(&opgrp
->pg_token
);
767 pgrel(opgrp
); /* manual pgref */
768 pgrel(opgrp
); /* p->p_pgrp ref */
770 lwkt_reltoken(&p
->p_token
);
771 lwkt_reltoken(&pgrp
->pg_token
);
779 * Remove process from process group
784 leavepgrp(struct proc
*p
)
786 struct pgrp
*pg
= p
->p_pgrp
;
788 lwkt_gettoken(&p
->p_token
);
789 while ((pg
= p
->p_pgrp
) != NULL
) {
791 lwkt_gettoken(&pg
->pg_token
);
792 if (p
->p_pgrp
!= pg
) {
793 lwkt_reltoken(&pg
->pg_token
);
798 LIST_REMOVE(p
, p_pglist
);
799 lwkt_reltoken(&pg
->pg_token
);
800 pgrel(pg
); /* manual pgref */
801 pgrel(pg
); /* p->p_pgrp ref */
804 lwkt_reltoken(&p
->p_token
);
810 * Adjust the ref count on a session structure. When the ref count falls to
811 * zero the tty is disassociated from the session and the session structure
812 * is freed. Note that tty assocation is not itself ref-counted.
817 sess_hold(struct session
*sp
)
819 atomic_add_int(&sp
->s_count
, 1);
826 sess_rele(struct session
*sess
)
833 n
= SESS_HASH(sess
->s_sid
);
837 count
= sess
->s_count
;
841 lwkt_gettoken(&tty_token
);
842 lwkt_gettoken(&prg
->proc_token
);
843 if (atomic_cmpset_int(&sess
->s_count
, 1, 0))
845 lwkt_reltoken(&prg
->proc_token
);
846 lwkt_reltoken(&tty_token
);
849 if (atomic_cmpset_int(&sess
->s_count
, count
, count
- 1))
856 * Successful 1->0 transition and tty_token is held.
858 LIST_REMOVE(sess
, s_list
);
859 if (pid_doms
[sess
->s_sid
% PIDSEL_DOMAINS
] != (uint8_t)time_second
)
860 pid_doms
[sess
->s_sid
% PIDSEL_DOMAINS
] = (uint8_t)time_second
;
862 if (sess
->s_ttyp
&& sess
->s_ttyp
->t_session
) {
863 #ifdef TTY_DO_FULL_CLOSE
864 /* FULL CLOSE, see ttyclearsession() */
865 KKASSERT(sess
->s_ttyp
->t_session
== sess
);
866 sess
->s_ttyp
->t_session
= NULL
;
868 /* HALF CLOSE, see ttyclearsession() */
869 if (sess
->s_ttyp
->t_session
== sess
)
870 sess
->s_ttyp
->t_session
= NULL
;
873 if ((tp
= sess
->s_ttyp
) != NULL
) {
877 lwkt_reltoken(&prg
->proc_token
);
878 lwkt_reltoken(&tty_token
);
880 kfree(sess
, M_SESSION
);
884 * Adjust pgrp jobc counters when specified process changes process group.
885 * We count the number of processes in each process group that "qualify"
886 * the group for terminal job control (those with a parent in a different
887 * process group of the same session). If that count reaches zero, the
888 * process group becomes orphaned. Check both the specified process'
889 * process group and that of its children.
890 * entering == 0 => p is leaving specified group.
891 * entering == 1 => p is entering specified group.
896 fixjobc(struct proc
*p
, struct pgrp
*pgrp
, int entering
)
898 struct pgrp
*hispgrp
;
899 struct session
*mysession
;
903 * Check p's parent to see whether p qualifies its own process
904 * group; if so, adjust count for p's process group.
906 lwkt_gettoken(&p
->p_token
); /* p_children scan */
907 lwkt_gettoken(&pgrp
->pg_token
);
909 mysession
= pgrp
->pg_session
;
910 if ((hispgrp
= p
->p_pptr
->p_pgrp
) != pgrp
&&
911 hispgrp
->pg_session
== mysession
) {
914 else if (--pgrp
->pg_jobc
== 0)
919 * Check this process' children to see whether they qualify
920 * their process groups; if so, adjust counts for children's
923 LIST_FOREACH(np
, &p
->p_children
, p_sibling
) {
925 lwkt_gettoken(&np
->p_token
);
926 if ((hispgrp
= np
->p_pgrp
) != pgrp
&&
927 hispgrp
->pg_session
== mysession
&&
928 np
->p_stat
!= SZOMB
) {
930 lwkt_gettoken(&hispgrp
->pg_token
);
933 else if (--hispgrp
->pg_jobc
== 0)
935 lwkt_reltoken(&hispgrp
->pg_token
);
938 lwkt_reltoken(&np
->p_token
);
941 KKASSERT(pgrp
->pg_refs
> 0);
942 lwkt_reltoken(&pgrp
->pg_token
);
943 lwkt_reltoken(&p
->p_token
);
947 * A process group has become orphaned;
948 * if there are any stopped processes in the group,
949 * hang-up all process in that group.
951 * The caller must hold pg_token.
954 orphanpg(struct pgrp
*pg
)
958 LIST_FOREACH(p
, &pg
->pg_members
, p_pglist
) {
959 if (p
->p_stat
== SSTOP
) {
960 LIST_FOREACH(p
, &pg
->pg_members
, p_pglist
) {
970 * Add a new process to the allproc list and the PID hash. This
971 * also assigns a pid to the new process.
976 proc_add_allproc(struct proc
*p
)
980 if ((random_offset
= randompid
) != 0) {
981 read_random(&random_offset
, sizeof(random_offset
));
982 random_offset
= (random_offset
& 0x7FFFFFFF) % randompid
;
984 proc_makepid(p
, random_offset
);
988 * Calculate a new process pid. This function is integrated into
989 * proc_add_allproc() to guarentee that the new pid is not reused before
990 * the new process can be added to the allproc list.
992 * p_pid is assigned and the process is added to the allproc hash table
994 * WARNING! We need to allocate PIDs sequentially during early boot.
995 * In particular, init needs to have a pid of 1.
999 proc_makepid(struct proc
*p
, int random_offset
)
1001 static pid_t nextpid
= 1; /* heuristic, allowed to race */
1005 struct session
*sess
;
1012 * Select the next pid base candidate.
1014 * Check cyclement, do not allow a pid < 100.
1018 base
= atomic_fetchadd_int(&nextpid
, 1) + random_offset
;
1019 if (base
<= 0 || base
>= PID_MAX
) {
1020 base
= base
% PID_MAX
;
1025 nextpid
= base
; /* reset (SMP race ok) */
1029 * Do not allow a base pid to be selected from a domain that has
1030 * recently seen a pid/pgid/sessid reap. Sleep a little if we looped
1031 * through all available domains.
1033 * WARNING: We want the early pids to be allocated linearly,
1034 * particularly pid 1 and pid 2.
1036 if (++retries
>= PIDSEL_DOMAINS
)
1037 tsleep(&nextpid
, 0, "makepid", 1);
1039 delta8
= (int8_t)time_second
-
1040 (int8_t)pid_doms
[base
% PIDSEL_DOMAINS
];
1041 if (delta8
>= 0 && delta8
<= PIDDOM_DELAY
) {
1048 * Calculate a hash index and find an unused process id within
1049 * the table, looping if we cannot find one.
1051 * The inner loop increments by ALLPROC_HSIZE which keeps the
1052 * PID at the same pid_doms[] index as well as the same hash index.
1054 n
= ALLPROC_HASH(base
);
1056 lwkt_gettoken(&prg
->proc_token
);
1059 LIST_FOREACH(ps
, &prg
->allproc
, p_list
) {
1060 if (ps
->p_pid
== base
) {
1061 base
+= ALLPROC_HSIZE
;
1062 if (base
>= PID_MAX
) {
1063 lwkt_reltoken(&prg
->proc_token
);
1070 LIST_FOREACH(pg
, &prg
->allpgrp
, pg_list
) {
1071 if (pg
->pg_id
== base
) {
1072 base
+= ALLPROC_HSIZE
;
1073 if (base
>= PID_MAX
) {
1074 lwkt_reltoken(&prg
->proc_token
);
1081 LIST_FOREACH(sess
, &prg
->allsess
, s_list
) {
1082 if (sess
->s_sid
== base
) {
1083 base
+= ALLPROC_HSIZE
;
1084 if (base
>= PID_MAX
) {
1085 lwkt_reltoken(&prg
->proc_token
);
1094 * Assign the pid and insert the process.
1097 LIST_INSERT_HEAD(&prg
->allproc
, p
, p_list
);
1098 lwkt_reltoken(&prg
->proc_token
);
1102 * Called from exit1 to place the process into a zombie state.
1103 * The process is removed from the pid hash and p_stat is set
1104 * to SZOMB. Normal pfind[n]() calls will not find it any more.
1106 * Caller must hold p->p_token. We are required to wait until p_lock
1107 * becomes zero before we can manipulate the list, allowing allproc
1108 * scans to guarantee consistency during a list scan.
1111 proc_move_allproc_zombie(struct proc
*p
)
1116 n
= ALLPROC_HASH(p
->p_pid
);
1118 PSTALL(p
, "reap1", 0);
1119 lwkt_gettoken(&prg
->proc_token
);
1121 PSTALL(p
, "reap1a", 0);
1124 lwkt_reltoken(&prg
->proc_token
);
1125 dsched_exit_proc(p
);
1129 * This routine is called from kern_wait() and will remove the process
1130 * from the zombie list and the sibling list. This routine will block
1131 * if someone has a lock on the proces (p_lock).
1133 * Caller must hold p->p_token. We are required to wait until p_lock
1134 * becomes zero before we can manipulate the list, allowing allproc
1135 * scans to guarantee consistency during a list scan.
1138 proc_remove_zombie(struct proc
*p
)
1143 n
= ALLPROC_HASH(p
->p_pid
);
1146 PSTALL(p
, "reap2", 0);
1147 lwkt_gettoken(&prg
->proc_token
);
1148 PSTALL(p
, "reap2a", 0);
1149 LIST_REMOVE(p
, p_list
); /* from remove master list */
1150 LIST_REMOVE(p
, p_sibling
); /* and from sibling list */
1152 if (pid_doms
[p
->p_pid
% PIDSEL_DOMAINS
] != (uint8_t)time_second
)
1153 pid_doms
[p
->p_pid
% PIDSEL_DOMAINS
] = (uint8_t)time_second
;
1154 lwkt_reltoken(&prg
->proc_token
);
1158 * Handle various requirements prior to returning to usermode. Called from
1159 * platform trap and system call code.
1162 lwpuserret(struct lwp
*lp
)
1164 struct proc
*p
= lp
->lwp_proc
;
1166 if (lp
->lwp_mpflags
& LWP_MP_VNLRU
) {
1167 atomic_clear_int(&lp
->lwp_mpflags
, LWP_MP_VNLRU
);
1170 if (lp
->lwp_mpflags
& LWP_MP_WEXIT
) {
1171 lwkt_gettoken(&p
->p_token
);
1173 lwkt_reltoken(&p
->p_token
); /* NOT REACHED */
1178 * Kernel threads run from user processes can also accumulate deferred
1179 * actions which need to be acted upon. Callers include:
1181 * nfsd - Can allocate lots of vnodes
1184 lwpkthreaddeferred(void)
1186 struct lwp
*lp
= curthread
->td_lwp
;
1189 if (lp
->lwp_mpflags
& LWP_MP_VNLRU
) {
1190 atomic_clear_int(&lp
->lwp_mpflags
, LWP_MP_VNLRU
);
1197 proc_usermap(struct proc
*p
, int invfork
)
1199 struct sys_upmap
*upmap
;
1201 lwkt_gettoken(&p
->p_token
);
1202 upmap
= kmalloc(roundup2(sizeof(*upmap
), PAGE_SIZE
), M_PROC
,
1204 if (p
->p_upmap
== NULL
) {
1205 upmap
->header
[0].type
= UKPTYPE_VERSION
;
1206 upmap
->header
[0].offset
= offsetof(struct sys_upmap
, version
);
1207 upmap
->header
[1].type
= UPTYPE_RUNTICKS
;
1208 upmap
->header
[1].offset
= offsetof(struct sys_upmap
, runticks
);
1209 upmap
->header
[2].type
= UPTYPE_FORKID
;
1210 upmap
->header
[2].offset
= offsetof(struct sys_upmap
, forkid
);
1211 upmap
->header
[3].type
= UPTYPE_PID
;
1212 upmap
->header
[3].offset
= offsetof(struct sys_upmap
, pid
);
1213 upmap
->header
[4].type
= UPTYPE_PROC_TITLE
;
1214 upmap
->header
[4].offset
= offsetof(struct sys_upmap
,proc_title
);
1215 upmap
->header
[5].type
= UPTYPE_INVFORK
;
1216 upmap
->header
[5].offset
= offsetof(struct sys_upmap
, invfork
);
1218 upmap
->version
= UPMAP_VERSION
;
1219 upmap
->pid
= p
->p_pid
;
1220 upmap
->forkid
= p
->p_forkid
;
1221 upmap
->invfork
= invfork
;
1224 kfree(upmap
, M_PROC
);
1226 lwkt_reltoken(&p
->p_token
);
1230 proc_userunmap(struct proc
*p
)
1232 struct sys_upmap
*upmap
;
1234 lwkt_gettoken(&p
->p_token
);
1235 if ((upmap
= p
->p_upmap
) != NULL
) {
1237 kfree(upmap
, M_PROC
);
1239 lwkt_reltoken(&p
->p_token
);
1243 * Scan all processes on the allproc list. The process is automatically
1244 * held for the callback. A return value of -1 terminates the loop.
1245 * Zombie procs are skipped.
1247 * The callback is made with the process held and proc_token held.
1249 * We limit the scan to the number of processes as-of the start of
1250 * the scan so as not to get caught up in an endless loop if new processes
1251 * are created more quickly than we can scan the old ones. Add a little
1252 * slop to try to catch edge cases since nprocs can race.
1257 allproc_scan(int (*callback
)(struct proc
*, void *), void *data
)
1259 int limit
= nprocs
+ ncpus
;
1265 * prg->proc_token protects the allproc list and PHOLD() prevents the
1266 * process from being removed from the allproc list or the zombproc
1269 for (n
= 0; n
< ALLPROC_HSIZE
; ++n
) {
1270 procglob_t
*prg
= &procglob
[n
];
1271 if (LIST_FIRST(&prg
->allproc
) == NULL
)
1273 lwkt_gettoken(&prg
->proc_token
);
1274 LIST_FOREACH(p
, &prg
->allproc
, p_list
) {
1275 if (p
->p_stat
== SZOMB
)
1278 r
= callback(p
, data
);
1285 lwkt_reltoken(&prg
->proc_token
);
1288 * Check if asked to stop early
1296 * Scan all lwps of processes on the allproc list. The lwp is automatically
1297 * held for the callback. A return value of -1 terminates the loop.
1299 * The callback is made with the proces and lwp both held, and proc_token held.
1304 alllwp_scan(int (*callback
)(struct lwp
*, void *), void *data
)
1311 for (n
= 0; n
< ALLPROC_HSIZE
; ++n
) {
1312 procglob_t
*prg
= &procglob
[n
];
1314 if (LIST_FIRST(&prg
->allproc
) == NULL
)
1316 lwkt_gettoken(&prg
->proc_token
);
1317 LIST_FOREACH(p
, &prg
->allproc
, p_list
) {
1318 if (p
->p_stat
== SZOMB
)
1321 lwkt_gettoken(&p
->p_token
);
1322 FOREACH_LWP_IN_PROC(lp
, p
) {
1324 r
= callback(lp
, data
);
1327 lwkt_reltoken(&p
->p_token
);
1332 lwkt_reltoken(&prg
->proc_token
);
1335 * Asked to exit early
1343 * Scan all processes on the zombproc list. The process is automatically
1344 * held for the callback. A return value of -1 terminates the loop.
1347 * The callback is made with the proces held and proc_token held.
1350 zombproc_scan(int (*callback
)(struct proc
*, void *), void *data
)
1357 * prg->proc_token protects the allproc list and PHOLD() prevents the
1358 * process from being removed from the allproc list or the zombproc
1361 for (n
= 0; n
< ALLPROC_HSIZE
; ++n
) {
1362 procglob_t
*prg
= &procglob
[n
];
1364 if (LIST_FIRST(&prg
->allproc
) == NULL
)
1366 lwkt_gettoken(&prg
->proc_token
);
1367 LIST_FOREACH(p
, &prg
->allproc
, p_list
) {
1368 if (p
->p_stat
!= SZOMB
)
1371 r
= callback(p
, data
);
1376 lwkt_reltoken(&prg
->proc_token
);
1379 * Check if asked to stop early
1386 #include "opt_ddb.h"
1388 #include <ddb/ddb.h>
1393 DB_SHOW_COMMAND(pgrpdump
, pgrpdump
)
1400 for (i
= 0; i
< ALLPROC_HSIZE
; ++i
) {
1403 if (LIST_EMPTY(&prg
->allpgrp
))
1405 kprintf("\tindx %d\n", i
);
1406 LIST_FOREACH(pgrp
, &prg
->allpgrp
, pg_list
) {
1407 kprintf("\tpgrp %p, pgid %ld, sess %p, "
1408 "sesscnt %d, mem %p\n",
1409 (void *)pgrp
, (long)pgrp
->pg_id
,
1410 (void *)pgrp
->pg_session
,
1411 pgrp
->pg_session
->s_count
,
1412 (void *)LIST_FIRST(&pgrp
->pg_members
));
1413 LIST_FOREACH(p
, &pgrp
->pg_members
, p_pglist
) {
1414 kprintf("\t\tpid %ld addr %p pgrp %p\n",
1415 (long)p
->p_pid
, (void *)p
,
1424 * The caller must hold proc_token.
1427 sysctl_out_proc(struct proc
*p
, struct sysctl_req
*req
, int flags
)
1429 struct kinfo_proc ki
;
1431 int skp
= 0, had_output
= 0;
1434 bzero(&ki
, sizeof(ki
));
1435 lwkt_gettoken_shared(&p
->p_token
);
1436 fill_kinfo_proc(p
, &ki
);
1437 if ((flags
& KERN_PROC_FLAG_LWP
) == 0)
1440 FOREACH_LWP_IN_PROC(lp
, p
) {
1442 fill_kinfo_lwp(lp
, &ki
.kp_lwp
);
1444 error
= SYSCTL_OUT(req
, &ki
, sizeof(ki
));
1451 lwkt_reltoken(&p
->p_token
);
1452 /* We need to output at least the proc, even if there is no lwp. */
1453 if (had_output
== 0) {
1454 error
= SYSCTL_OUT(req
, &ki
, sizeof(ki
));
1460 * The caller must hold proc_token.
1463 sysctl_out_proc_kthread(struct thread
*td
, struct sysctl_req
*req
)
1465 struct kinfo_proc ki
;
1468 fill_kinfo_proc_kthread(td
, &ki
);
1469 error
= SYSCTL_OUT(req
, &ki
, sizeof(ki
));
1479 sysctl_kern_proc(SYSCTL_HANDLER_ARGS
)
1481 int *name
= (int *)arg1
;
1482 int oid
= oidp
->oid_number
;
1483 u_int namelen
= arg2
;
1486 struct thread
*marker
;
1491 struct ucred
*cr1
= curproc
->p_ucred
;
1493 flags
= oid
& KERN_PROC_FLAGMASK
;
1494 oid
&= ~KERN_PROC_FLAGMASK
;
1496 if ((oid
== KERN_PROC_ALL
&& namelen
!= 0) ||
1497 (oid
!= KERN_PROC_ALL
&& namelen
!= 1)) {
1502 * proc_token protects the allproc list and PHOLD() prevents the
1503 * process from being removed from the allproc list or the zombproc
1506 if (oid
== KERN_PROC_PID
) {
1507 p
= pfind((pid_t
)name
[0]);
1509 if (PRISON_CHECK(cr1
, p
->p_ucred
))
1510 error
= sysctl_out_proc(p
, req
, flags
);
1518 /* overestimate by 5 procs */
1519 error
= SYSCTL_OUT(req
, 0, sizeof (struct kinfo_proc
) * 5);
1524 for (n
= 0; n
< ALLPROC_HSIZE
; ++n
) {
1525 procglob_t
*prg
= &procglob
[n
];
1527 if (LIST_EMPTY(&prg
->allproc
))
1529 lwkt_gettoken_shared(&prg
->proc_token
);
1530 LIST_FOREACH(p
, &prg
->allproc
, p_list
) {
1532 * Show a user only their processes.
1534 if ((!ps_showallprocs
) &&
1535 (p
->p_ucred
== NULL
|| p_trespass(cr1
, p
->p_ucred
))) {
1539 * Skip embryonic processes.
1541 if (p
->p_stat
== SIDL
)
1544 * TODO - make more efficient (see notes below).
1548 case KERN_PROC_PGRP
:
1549 /* could do this by traversing pgrp */
1550 if (p
->p_pgrp
== NULL
||
1551 p
->p_pgrp
->pg_id
!= (pid_t
)name
[0])
1556 if ((p
->p_flags
& P_CONTROLT
) == 0 ||
1557 p
->p_session
== NULL
||
1558 p
->p_session
->s_ttyp
== NULL
||
1559 dev2udev(p
->p_session
->s_ttyp
->t_dev
) !=
1565 if (p
->p_ucred
== NULL
||
1566 p
->p_ucred
->cr_uid
!= (uid_t
)name
[0])
1570 case KERN_PROC_RUID
:
1571 if (p
->p_ucred
== NULL
||
1572 p
->p_ucred
->cr_ruid
!= (uid_t
)name
[0])
1577 if (!PRISON_CHECK(cr1
, p
->p_ucred
))
1580 error
= sysctl_out_proc(p
, req
, flags
);
1583 lwkt_reltoken(&prg
->proc_token
);
1587 lwkt_reltoken(&prg
->proc_token
);
1591 * Iterate over all active cpus and scan their thread list. Start
1592 * with the next logical cpu and end with our original cpu. We
1593 * migrate our own thread to each target cpu in order to safely scan
1594 * its thread list. In the last loop we migrate back to our original
1597 origcpu
= mycpu
->gd_cpuid
;
1598 if (!ps_showallthreads
|| jailed(cr1
))
1601 marker
= kmalloc(sizeof(struct thread
), M_TEMP
, M_WAITOK
|M_ZERO
);
1602 marker
->td_flags
= TDF_MARKER
;
1605 for (n
= 1; n
<= ncpus
; ++n
) {
1609 nid
= (origcpu
+ n
) % ncpus
;
1610 if (CPUMASK_TESTBIT(smp_active_mask
, nid
) == 0)
1612 rgd
= globaldata_find(nid
);
1613 lwkt_setcpu_self(rgd
);
1616 TAILQ_INSERT_TAIL(&rgd
->gd_tdallq
, marker
, td_allq
);
1618 while ((td
= TAILQ_PREV(marker
, lwkt_queue
, td_allq
)) != NULL
) {
1619 TAILQ_REMOVE(&rgd
->gd_tdallq
, marker
, td_allq
);
1620 TAILQ_INSERT_BEFORE(td
, marker
, td_allq
);
1621 if (td
->td_flags
& TDF_MARKER
)
1630 case KERN_PROC_PGRP
:
1633 case KERN_PROC_RUID
:
1636 error
= sysctl_out_proc_kthread(td
, req
);
1644 TAILQ_REMOVE(&rgd
->gd_tdallq
, marker
, td_allq
);
1652 * Userland scheduler expects us to return on the same cpu we
1655 if (mycpu
->gd_cpuid
!= origcpu
)
1656 lwkt_setcpu_self(globaldata_find(origcpu
));
1658 kfree(marker
, M_TEMP
);
1665 * This sysctl allows a process to retrieve the argument list or process
1666 * title for another process without groping around in the address space
1667 * of the other process. It also allow a process to set its own "process
1668 * title to a string of its own choice.
1673 sysctl_kern_proc_args(SYSCTL_HANDLER_ARGS
)
1675 int *name
= (int*) arg1
;
1676 u_int namelen
= arg2
;
1681 struct ucred
*cr1
= curproc
->p_ucred
;
1686 p
= pfind((pid_t
)name
[0]);
1689 lwkt_gettoken(&p
->p_token
);
1691 if ((!ps_argsopen
) && p_trespass(cr1
, p
->p_ucred
))
1694 if (req
->newptr
&& curproc
!= p
) {
1699 if (p
->p_upmap
!= NULL
&& p
->p_upmap
->proc_title
[0]) {
1701 * Args set via writable user process mmap.
1702 * We must calculate the string length manually
1703 * because the user data can change at any time.
1708 base
= p
->p_upmap
->proc_title
;
1709 for (n
= 0; n
< UPMAP_MAXPROCTITLE
- 1; ++n
) {
1713 error
= SYSCTL_OUT(req
, base
, n
);
1715 error
= SYSCTL_OUT(req
, "", 1);
1716 } else if ((pa
= p
->p_args
) != NULL
) {
1718 * Args set by setproctitle() sysctl.
1720 refcount_acquire(&pa
->ar_ref
);
1721 error
= SYSCTL_OUT(req
, pa
->ar_args
, pa
->ar_length
);
1722 if (refcount_release(&pa
->ar_ref
))
1726 if (req
->newptr
== NULL
)
1729 if (req
->newlen
+ sizeof(struct pargs
) > ps_arg_cache_limit
) {
1733 pa
= kmalloc(sizeof(struct pargs
) + req
->newlen
, M_PARGS
, M_WAITOK
);
1734 refcount_init(&pa
->ar_ref
, 1);
1735 pa
->ar_length
= req
->newlen
;
1736 error
= SYSCTL_IN(req
, pa
->ar_args
, req
->newlen
);
1744 * Replace p_args with the new pa. p_args may have previously
1751 KKASSERT(opa
->ar_ref
> 0);
1752 if (refcount_release(&opa
->ar_ref
)) {
1753 kfree(opa
, M_PARGS
);
1759 lwkt_reltoken(&p
->p_token
);
1766 sysctl_kern_proc_cwd(SYSCTL_HANDLER_ARGS
)
1768 int *name
= (int*) arg1
;
1769 u_int namelen
= arg2
;
1772 char *fullpath
, *freepath
;
1773 struct ucred
*cr1
= curproc
->p_ucred
;
1778 p
= pfind((pid_t
)name
[0]);
1781 lwkt_gettoken_shared(&p
->p_token
);
1784 * If we are not allowed to see other args, we certainly shouldn't
1785 * get the cwd either. Also check the usual trespassing.
1787 if ((!ps_argsopen
) && p_trespass(cr1
, p
->p_ucred
))
1790 if (req
->oldptr
&& p
->p_fd
!= NULL
&& p
->p_fd
->fd_ncdir
.ncp
) {
1791 struct nchandle nch
;
1793 cache_copy(&p
->p_fd
->fd_ncdir
, &nch
);
1794 error
= cache_fullpath(p
, &nch
, NULL
,
1795 &fullpath
, &freepath
, 0);
1799 error
= SYSCTL_OUT(req
, fullpath
, strlen(fullpath
) + 1);
1800 kfree(freepath
, M_TEMP
);
1805 lwkt_reltoken(&p
->p_token
);
1812 * This sysctl allows a process to retrieve the path of the executable for
1813 * itself or another process.
1816 sysctl_kern_proc_pathname(SYSCTL_HANDLER_ARGS
)
1818 pid_t
*pidp
= (pid_t
*)arg1
;
1819 unsigned int arglen
= arg2
;
1821 char *retbuf
, *freebuf
;
1823 struct nchandle nch
;
1827 if (*pidp
== -1) { /* -1 means this process */
1835 cache_copy(&p
->p_textnch
, &nch
);
1836 error
= cache_fullpath(p
, &nch
, NULL
, &retbuf
, &freebuf
, 0);
1840 error
= SYSCTL_OUT(req
, retbuf
, strlen(retbuf
) + 1);
1841 kfree(freebuf
, M_TEMP
);
1850 sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS
)
1852 /*int *name = (int *)arg1;*/
1853 u_int namelen
= arg2
;
1854 struct kinfo_sigtramp kst
;
1855 const struct sysentvec
*sv
;
1860 /* ignore pid if passed in (freebsd compatibility) */
1862 sv
= curproc
->p_sysent
;
1863 bzero(&kst
, sizeof(kst
));
1864 if (sv
->sv_szsigcode
) {
1867 sigbase
= trunc_page64((intptr_t)PS_STRINGS
-
1870 kst
.ksigtramp_start
= (void *)sigbase
;
1871 kst
.ksigtramp_end
= (void *)(sigbase
+ *sv
->sv_szsigcode
);
1873 error
= SYSCTL_OUT(req
, &kst
, sizeof(kst
));
1878 SYSCTL_NODE(_kern
, KERN_PROC
, proc
, CTLFLAG_RD
, 0, "Process table");
1880 SYSCTL_PROC(_kern_proc
, KERN_PROC_ALL
, all
, CTLFLAG_RD
|CTLTYPE_STRUCT
,
1881 0, 0, sysctl_kern_proc
, "S,proc", "Return entire process table");
1883 SYSCTL_NODE(_kern_proc
, KERN_PROC_PGRP
, pgrp
, CTLFLAG_RD
,
1884 sysctl_kern_proc
, "Process table");
1886 SYSCTL_NODE(_kern_proc
, KERN_PROC_TTY
, tty
, CTLFLAG_RD
,
1887 sysctl_kern_proc
, "Process table");
1889 SYSCTL_NODE(_kern_proc
, KERN_PROC_UID
, uid
, CTLFLAG_RD
,
1890 sysctl_kern_proc
, "Process table");
1892 SYSCTL_NODE(_kern_proc
, KERN_PROC_RUID
, ruid
, CTLFLAG_RD
,
1893 sysctl_kern_proc
, "Process table");
1895 SYSCTL_NODE(_kern_proc
, KERN_PROC_PID
, pid
, CTLFLAG_RD
,
1896 sysctl_kern_proc
, "Process table");
1898 SYSCTL_NODE(_kern_proc
, (KERN_PROC_ALL
| KERN_PROC_FLAG_LWP
), all_lwp
, CTLFLAG_RD
,
1899 sysctl_kern_proc
, "Process table");
1901 SYSCTL_NODE(_kern_proc
, (KERN_PROC_PGRP
| KERN_PROC_FLAG_LWP
), pgrp_lwp
, CTLFLAG_RD
,
1902 sysctl_kern_proc
, "Process table");
1904 SYSCTL_NODE(_kern_proc
, (KERN_PROC_TTY
| KERN_PROC_FLAG_LWP
), tty_lwp
, CTLFLAG_RD
,
1905 sysctl_kern_proc
, "Process table");
1907 SYSCTL_NODE(_kern_proc
, (KERN_PROC_UID
| KERN_PROC_FLAG_LWP
), uid_lwp
, CTLFLAG_RD
,
1908 sysctl_kern_proc
, "Process table");
1910 SYSCTL_NODE(_kern_proc
, (KERN_PROC_RUID
| KERN_PROC_FLAG_LWP
), ruid_lwp
, CTLFLAG_RD
,
1911 sysctl_kern_proc
, "Process table");
1913 SYSCTL_NODE(_kern_proc
, (KERN_PROC_PID
| KERN_PROC_FLAG_LWP
), pid_lwp
, CTLFLAG_RD
,
1914 sysctl_kern_proc
, "Process table");
1916 SYSCTL_NODE(_kern_proc
, KERN_PROC_ARGS
, args
, CTLFLAG_RW
| CTLFLAG_ANYBODY
,
1917 sysctl_kern_proc_args
, "Process argument list");
1919 SYSCTL_NODE(_kern_proc
, KERN_PROC_CWD
, cwd
, CTLFLAG_RD
| CTLFLAG_ANYBODY
,
1920 sysctl_kern_proc_cwd
, "Process argument list");
1922 static SYSCTL_NODE(_kern_proc
, KERN_PROC_PATHNAME
, pathname
, CTLFLAG_RD
,
1923 sysctl_kern_proc_pathname
, "Process executable path");
1925 SYSCTL_PROC(_kern_proc
, KERN_PROC_SIGTRAMP
, sigtramp
, CTLFLAG_RD
|CTLTYPE_STRUCT
,
1926 0, 0, sysctl_kern_proc_sigtramp
, "S,sigtramp",
1927 "Return sigtramp address range");