Date: Mon, 8 Jun 2009 19:13:26 -0800 From: Mel Flynn <mel.flynn+fbsd.questions@mailing.thruhere.net> To: freebsd-questions@freebsd.org Cc: yuri@rawbw.com, "Paul B. Mahol" <onemda@gmail.com> Subject: Re: What is the equivalent of Linux command 'ps --forest'? Message-ID: <200906081913.26703.mel.flynn%2Bfbsd.questions@mailing.thruhere.net> In-Reply-To: <3a142e750906051012u73178f76wfe4ee3726414c1a2@mail.gmail.com> References: <4A294E6A.7070205@rawbw.com> <3a142e750906051012u73178f76wfe4ee3726414c1a2@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 05 June 2009 09:12:08 Paul B. Mahol wrote: > On 6/5/09, Yuri <yuri@rawbw.com> 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 <file> (- 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 <user>\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 */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906081913.26703.mel.flynn%2Bfbsd.questions>