db_ps.c revision 85207
12322Sdg/*-
22322Sdg * Copyright (c) 1993 The Regents of the University of California.
32322Sdg * All rights reserved.
42322Sdg *
52322Sdg * Redistribution and use in source and binary forms, with or without
62322Sdg * modification, are permitted provided that the following conditions
72322Sdg * are met:
82322Sdg * 1. Redistributions of source code must retain the above copyright
92322Sdg *    notice, this list of conditions and the following disclaimer.
102322Sdg * 2. Redistributions in binary form must reproduce the above copyright
112322Sdg *    notice, this list of conditions and the following disclaimer in the
122322Sdg *    documentation and/or other materials provided with the distribution.
132322Sdg * 3. All advertising materials mentioning features or use of this software
142322Sdg *    must display the following acknowledgement:
152322Sdg *	This product includes software developed by the University of
162322Sdg *	California, Berkeley and its contributors.
172322Sdg * 4. Neither the name of the University nor the names of its contributors
182322Sdg *    may be used to endorse or promote products derived from this software
192322Sdg *    without specific prior written permission.
202322Sdg *
212322Sdg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
222322Sdg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
232322Sdg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
242322Sdg * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
252322Sdg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
262322Sdg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
272322Sdg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
282322Sdg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
292322Sdg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
302322Sdg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
312322Sdg * SUCH DAMAGE.
322322Sdg *
3350477Speter * $FreeBSD: head/sys/ddb/db_ps.c 85207 2001-10-20 03:22:23Z jhb $
342322Sdg */
352322Sdg#include <sys/param.h>
362322Sdg#include <sys/systm.h>
3774914Sjhb#include <sys/lock.h>
3874914Sjhb#include <sys/mutex.h>
392322Sdg#include <sys/proc.h>
4049558Sphk#include <sys/cons.h>
4112734Sbde
4212734Sbde#include <ddb/ddb.h>
4312734Sbde
442322Sdgvoid
4510349Sbdedb_ps(dummy1, dummy2, dummy3, dummy4)
4610349Sbde	db_expr_t	dummy1;
4710349Sbde	boolean_t	dummy2;
4810349Sbde	db_expr_t	dummy3;
4910349Sbde	char *		dummy4;
5010349Sbde{
512322Sdg	int np;
522322Sdg	int nl = 0;
5310128Sdg	volatile struct proc *p, *pp;
5485207Sjhb	volatile struct thread *td;
5510128Sdg
562322Sdg	np = nprocs;
572322Sdg
5870527Sphk	if (!LIST_EMPTY(&allproc))
5970527Sphk		p = LIST_FIRST(&allproc);
6010128Sdg	else
6110128Sdg		p = &proc0;
6210128Sdg
6385207Sjhb	db_printf("  pid   proc     addr    uid  ppid  pgrp  flag  stat wmesg   wchan   cmd\n");
642322Sdg	while (--np >= 0) {
652322Sdg		/*
662322Sdg		 * XXX just take 20 for now...
672322Sdg		 */
682322Sdg		if (nl++ == 20) {
6910128Sdg			int c;
7010128Sdg
712322Sdg			db_printf("--More--");
7210128Sdg			c = cngetc();
732322Sdg			db_printf("\r");
7410128Sdg			/*
7510128Sdg			 * A whole screenfull or just one line?
7610128Sdg			 */
7710128Sdg			switch (c) {
7810128Sdg			case '\n':		/* just one line */
7930239Sbde				nl = 20;
8010128Sdg				break;
8110128Sdg			case ' ':
8210128Sdg				nl = 0;		/* another screenfull */
8310128Sdg				break;
8410128Sdg			default:		/* exit */
8510128Sdg				db_printf("\n");
8610128Sdg				return;
8710128Sdg			}
882322Sdg		}
8916381Speter		if (p == NULL) {
9016381Speter			printf("oops, ran out of processes early!\n");
9116381Speter			break;
9216381Speter		}
932322Sdg		pp = p->p_pptr;
9410128Sdg		if (pp == NULL)
952322Sdg			pp = p;
9610128Sdg
9785207Sjhb		db_printf("%5d %8p %8p %4d %5d %5d %07x  %d",
9883383Sjhb		    p->p_pid, (volatile void *)p, (void *)p->p_uarea,
9983383Sjhb		    p->p_ucred ? p->p_ucred->cr_ruid : 0, pp->p_pid,
10083383Sjhb		    p->p_pgrp ? p->p_pgrp->pg_id : 0, p->p_flag, p->p_stat);
10183366Sjulian		if (p->p_flag & P_KSES) {
10283383Sjhb			db_printf("(threaded)  %s\n", p->p_comm);
10383366Sjulian			FOREACH_THREAD_IN_PROC(p, td) {
10483366Sjulian				db_printf( ".  .  .  .  .  .  .  "
10583366Sjulian				           ".  .  .  .  .  .  .  .  ");
10683366Sjulian				if (td->td_wchan) {
10783383Sjhb					db_printf("%6s %8p", td->td_wmesg,
10883383Sjhb					    (void *)td->td_wchan);
10985207Sjhb				} else if (p->p_stat == SMTX) {
11085207Sjhb					db_printf("%6s %8p", td->td_mtxname,
11185207Sjhb					    (void *)td->td_blocked);
11283366Sjulian				} else {
11383366Sjulian					db_printf("--not blocked--");
11483366Sjulian				}
11583366Sjulian			}
11610128Sdg		} else {
11785207Sjhb			td = &p->p_thread;
11885207Sjhb			if (td->td_wchan) {
11985207Sjhb				db_printf("  %6s %8p", td->td_wmesg,
12085207Sjhb				    (void *)td->td_wchan);
12185207Sjhb			} else if (p->p_stat == SMTX) {
12285207Sjhb				db_printf("  %6s %8p", td->td_mtxname,
12385207Sjhb				    (void *)td->td_blocked);
12483366Sjulian			} else {
12583366Sjulian				db_printf("                 ");
12683366Sjulian			}
12783383Sjhb			db_printf(" %s\n", p->p_comm);
1282322Sdg		}
12970527Sphk		p = LIST_NEXT(p, p_list);
13010128Sdg		if (p == NULL && np > 0)
13170527Sphk			p = LIST_FIRST(&zombproc);
1322322Sdg    	}
1332322Sdg}
134