2 * Copyright (c) 1993 The Regents of the University of California.
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 * 4. 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/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/mutex.h>
40 #include <vm/vm_param.h>
45 static void dumpthread(volatile struct proc *p, volatile struct thread *td);
48 db_ps(dummy1, dummy2, dummy3, dummy4)
54 volatile struct proc *p, *pp;
55 volatile struct thread *td;
62 /* sx_slock(&allproc_lock); */
63 if (!LIST_EMPTY(&allproc))
64 p = LIST_FIRST(&allproc);
68 db_setup_paging(db_simple_pager, &quit, db_lines_per_page);
69 db_printf(" pid proc uid ppid pgrp flag stat wmesg wchan cmd\n");
70 while (--np >= 0 && !quit) {
72 printf("oops, ran out of processes early!\n");
98 db_printf("%5d %8p %4d %5d %5d %07x %s",
99 p->p_pid, (volatile void *)p,
100 p->p_ucred != NULL ? p->p_ucred->cr_ruid : 0, pp->p_pid,
101 p->p_pgrp != NULL ? p->p_pgrp->pg_id : 0, p->p_flag,
103 if (p->p_flag & P_HADTHREADS)
104 db_printf("(threaded) %s\n", p->p_comm);
105 FOREACH_THREAD_IN_PROC(p, td) {
110 /* PROC_UNLOCK(p); */
112 p = LIST_NEXT(p, p_list);
113 if (p == NULL && np > 0)
114 p = LIST_FIRST(&zombproc);
116 /* sx_sunlock(&allproc_lock); */
120 dumpthread(volatile struct proc *p, volatile struct thread *td)
123 if (p->p_flag & P_HADTHREADS)
124 db_printf( " thread %p ksegrp %p ", td, td->td_ksegrp);
125 if (TD_ON_SLEEPQ(td))
126 db_printf("[SLPQ %s %p]", td->td_wmesg, (void *)td->td_wchan);
127 switch (td->td_state) {
129 if (TD_ON_LOCK(td)) {
130 db_printf("[LOCK %6s %8p]",
132 (void *)td->td_blocked);
134 if (TD_IS_SLEEPING(td)) {
137 if (TD_IS_SWAPPED(td)) {
140 if (TD_IS_SUSPENDED(td)) {
143 if (TD_AWAITING_INTR(td)) {
144 db_printf("[IWAIT]");
148 db_printf("[Can run]");
154 db_printf("[CPU %d]", td->td_oncpu);
157 db_printf("[INACTIVE]");
160 db_printf("[UNK: %#x]", td->td_state);
162 if (p->p_flag & P_HADTHREADS) {
165 db_printf("[kse %p]", td->td_kse);
169 db_printf(" %s\n", p->p_comm);