From owner-freebsd-questions@FreeBSD.ORG Tue Jun 9 03:13:57 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D5A41106564A for ; Tue, 9 Jun 2009 03:13:57 +0000 (UTC) (envelope-from mel.flynn+fbsd.questions@mailing.thruhere.net) Received: from mailhub.rachie.is-a-geek.net (rachie.is-a-geek.net [66.230.99.27]) by mx1.freebsd.org (Postfix) with ESMTP id 8EDC38FC1E for ; Tue, 9 Jun 2009 03:13:57 +0000 (UTC) (envelope-from mel.flynn+fbsd.questions@mailing.thruhere.net) Received: from smoochies.rachie.is-a-geek.net (mailhub.lan.rachie.is-a-geek.net [192.168.2.11]) by mailhub.rachie.is-a-geek.net (Postfix) with ESMTP id 5D6297E837; Mon, 8 Jun 2009 19:13:56 -0800 (AKDT) From: Mel Flynn To: freebsd-questions@freebsd.org Date: Mon, 8 Jun 2009 19:13:26 -0800 User-Agent: KMail/1.11.3 (FreeBSD/8.0-CURRENT; KDE/4.2.3; i386; ; ) References: <4A294E6A.7070205@rawbw.com> <3a142e750906051012u73178f76wfe4ee3726414c1a2@mail.gmail.com> In-Reply-To: <3a142e750906051012u73178f76wfe4ee3726414c1a2@mail.gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200906081913.26703.mel.flynn+fbsd.questions@mailing.thruhere.net> Cc: yuri@rawbw.com, "Paul B. Mahol" Subject: Re: What is the equivalent of Linux command 'ps --forest'? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Jun 2009 03:13:58 -0000 On Friday 05 June 2009 09:12:08 Paul B. Mahol wrote: > On 6/5/09, Yuri wrote: > > How can I see processes in a hierarchical way? > > http://lists.freebsd.org/pipermail/svn-src-head/2009-May/006912.html > > or pstree from ports. And if in a jail, you can use the patch below to add jail support via -j switch. -- Mel --- pstree.c.orig 2007-10-26 11:39:50.000000000 -0800 +++ pstree.c 2008-09-20 00:30:53.000000000 -0800 @@ -189,7 +189,7 @@ { "qq", "qw", "`", "q", "t", "x", "m", "\016", "\017", "\033(B\033)0" } /*Vt100*/ }, *C; -int MyPid, NProc, Columns, RootPid; +int MyPid, NProc, Columns, RootPid, jFlag; short showall = TRUE, soption = FALSE, Uoption = FALSE; char *name = "", *str = NULL, *Progname; long ipid = -1; @@ -464,6 +464,27 @@ exit(1); } + /* If this is a FreeBSD jail(8), create a fake root process 'jailinit', which + * serves as starting point for the tree. */ + if( jFlag ) + { + P = realloc(P, (i+1) * sizeof(struct Proc)); + if (P == NULL) { + fprintf(stderr, "Problems with realloc.\n"); + exit(1); + } + memset(&P[i], 0, sizeof(*P)); + P[i].uid = 0; + (void)strncpy(P[i].name, "root", sizeof(P[i].name)); + P[i].pid = 1; + P[i].ppid = 0; + P[i].pgid = 1; + P[i].thcount = 1; + (void)strncpy(P[i].cmd, "/sbin/jailinit", sizeof(P[i].cmd)); + P[i].parent = P[i].child = P[i].sister = -1; + P[i].print = FALSE; + i++; + } while (NULL != fgets(line, MAXLINE, tn)) { int len, num; len = strlen(line); @@ -728,6 +749,7 @@ " -f file read input from (- is stdin) instead of running\n" " \"%s\"\n" " -g n use graphics chars for tree. n=1: IBM-850, n=2: VT100\n" + " -j Assume running in a FreeBSD jail (no root process)\n" " -l n print tree to n level deep\n" " -u user show only branches containing processes of \n" " -U don't show branches containing only root processes\n" @@ -756,7 +778,7 @@ Progname = strrchr(argv[0],'/'); Progname = (NULL == Progname) ? argv[0] : Progname + 1; - while ((ch = getopt(argc, argv, "df:g:hl:p:s:u:Uw?")) != EOF) + while ((ch = getopt(argc, argv, "df:g:hjl:p:s:u:Uw?")) != EOF) switch(ch) { /*case 'a': align = TRUE; @@ -778,6 +800,9 @@ } C = &TreeChars[graph]; break; + case 'j' : + jFlag = 1; + break; case 'l': /* LOPTION */ maxLdepth = atoi(optarg); /* LOPTION */ if(maxLdepth < 1) maxLdepth = 1; /* LOPTION */