db_ps.c revision 10128
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 * 3310128Sdg * $Id: db_ps.c,v 1.6 1995/05/30 07:57:07 rgrimes Exp $ 342322Sdg */ 352322Sdg#include <sys/param.h> 362322Sdg#include <sys/systm.h> 372322Sdg#include <sys/proc.h> 383173Sphk#include <ddb/ddb.h> 393149Sphk#include <machine/cons.h> 402322Sdg 412322Sdgvoid 422322Sdgdb_ps() { 432322Sdg int np; 442322Sdg int nl = 0; 4510128Sdg volatile struct proc *p, *pp; 4610128Sdg 472322Sdg np = nprocs; 482322Sdg 4910128Sdg if (allproc != NULL) 5010128Sdg p = allproc; 5110128Sdg else 5210128Sdg p = &proc0; 5310128Sdg 547454Sdg db_printf(" pid proc addr uid ppid pgrp flag stat wmesg wchan cmd\n"); 552322Sdg while (--np >= 0) { 562322Sdg /* 572322Sdg * XXX just take 20 for now... 582322Sdg */ 592322Sdg if (nl++ == 20) { 6010128Sdg int c; 6110128Sdg 622322Sdg db_printf("--More--"); 6310128Sdg c = cngetc(); 642322Sdg db_printf("\r"); 6510128Sdg /* 6610128Sdg * A whole screenfull or just one line? 6710128Sdg */ 6810128Sdg switch (c) { 6910128Sdg case '\n': /* just one line */ 7010128Sdg nl = 19; 7110128Sdg break; 7210128Sdg case ' ': 7310128Sdg nl = 0; /* another screenfull */ 7410128Sdg break; 7510128Sdg default: /* exit */ 7610128Sdg db_printf("\n"); 7710128Sdg return; 7810128Sdg } 792322Sdg } 802322Sdg pp = p->p_pptr; 8110128Sdg if (pp == NULL) 822322Sdg pp = p; 8310128Sdg 8410128Sdg db_printf("%5d %06x %06x %4d %5d %5d %06x %d", 8510128Sdg p->p_pid, p, p->p_addr, p->p_cred ? p->p_cred->p_ruid : 0, 8610128Sdg pp->p_pid, p->p_pgrp ? p->p_pgrp->pg_id : 0, p->p_flag, p->p_stat); 8710128Sdg if (p->p_wchan) { 8810128Sdg db_printf(" %6s %08x", p->p_wmesg, p->p_wchan); 8910128Sdg } else { 9010128Sdg db_printf(" "); 912322Sdg } 9210128Sdg db_printf(" %s\n", p->p_comm ? p->p_comm : ""); 9310128Sdg 9410128Sdg p = p->p_next; 9510128Sdg if (p == NULL && np > 0) 9610128Sdg p = zombproc; 972322Sdg } 982322Sdg} 99