From owner-freebsd-current Tue Jun 11 16: 9:54 2002 Delivered-To: freebsd-current@freebsd.org Received: from smtp.noos.fr (claudel.noos.net [212.198.2.83]) by hub.freebsd.org (Postfix) with ESMTP id 3184C37B40D for ; Tue, 11 Jun 2002 16:09:43 -0700 (PDT) Received: (qmail 11111959 invoked by uid 0); 11 Jun 2002 23:09:41 -0000 Received: from unknown (HELO gits.gits.dyndns.org) ([212.198.230.194]) (envelope-sender ) by 212.198.2.83 (qmail-ldap-1.03) with SMTP for ; 11 Jun 2002 23:09:41 -0000 Received: from gits.gits.dyndns.org (btzkpq2rhm5uvbke@localhost [127.0.0.1]) by gits.gits.dyndns.org (8.12.3/8.12.3) with ESMTP id g5BN9ea6018711; Wed, 12 Jun 2002 01:09:40 +0200 (CEST) (envelope-from root@gits.dyndns.org) Received: (from root@localhost) by gits.gits.dyndns.org (8.12.3/8.12.3/Submit) id g5BN9dKt018686; Wed, 12 Jun 2002 01:09:39 +0200 (CEST) (envelope-from root) Date: Wed, 12 Jun 2002 01:09:38 +0200 From: Cyrille Lefevre To: Juli Mallett Cc: current@FreeBSD.org Subject: Re: Looking for comments on a new utility... Message-ID: <20020611230938.GA24547@gits.dyndns.org> References: <20020611051517.A87966@FreeBSD.ORG> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="J/dobhs11T7y2rNN" Content-Disposition: inline In-Reply-To: <20020611051517.A87966@FreeBSD.ORG> User-Agent: Mutt/1.3.99i Organization: ACME X-Face: V|+c;4!|B?E%BE^{E6);aI.[< List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --J/dobhs11T7y2rNN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jun 11, 2002 at 05:15:17AM -0700, Juli Mallett wrote: > Hej, > > As some of you may have noticed, I've done some poking of ps(1) lately, and > this has brought attention of people who have ideas for things that they > would like to see done to ps(1) :) The most notable request was for a > feature I've missed having in our ps(1) for a while, the ability to get a > tree of processes printed so you can tell who is whose child, etc. > > ps(1)'s internals, however, didn't seem quite right to me, but after about > 10 minutes reading kvm(3) manpages and recalling some tricks with recursive > programming to produce an N-level tree with as many as N-1 elements, I had > come up with a simple utility to print out a "process tree". > > You can find the code here: > http://people.freebsd.org/~jmallett/.proctree/proctree.c > > And some example output from a cluster machine here: > http://people.freebsd.org/~jmallett/.proctree/proctree.out > Lots of people have given feedback that they don't care much for the \_ > formatting of the tree, and I'm willing to look at patches that provide > noticably more readable output. how about this one ? 1 ? 0 \_ init 2814 ttyp0 0 \_ sh 2816 ttyp0 0 | \_ sh 57423 ? 0 | \_ sleep 2596 ? 0 \_ inetd 24834 ? 0 | \_ rlogind 24838 ttyp0 0 | | \_ ksh 24912 ttyp0 0 | | \_ ksh 57504 ? 0 | \_ telnetd ^^^^^^^^^^^^^^^^^^^^^^ command tree ^^^^^^^^^^^^^^^^^^^^ standard ps fields taken from ast-open `ps -T'. see http://www.research.att.com/~gsf/download/tgz/ for details (maybe one I'll will finish this !@#$%^&* port which is still broken in some way ?) for fun, how about a simple awk script like the one in attachment ;^) Cyrille. -- Cyrille Lefevre mailto:cyrille.lefevre@laposte.net --J/dobhs11T7y2rNN Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=pstree #!/bin/sh # was ps -ef ps axwo "user pid ppid start tt time command" | awk ' BEGIN { getline } { if (! nchild[$3]) nchild[$3] = 0 father[$2] = $3 children[$3, nchild[$3]] = $2 nchild[$3] ++ start[$2] = $4 tty[$2] = $5 time[$2] = $6 cmd[$2] = $7 for (i = 8; i <= NF; i++) cmd[$2] = cmd[$2] " " $i } function print_parents(pid) { if (pid != 1) prefix = " " print_parents(father[pid]) else prefix = " " printf "%6i %6i %7s %s %s %s\\_ %s\n", \ pid, father[pid], start[pid], tty[pid], time[pid], \ substr(prefix, 1, length(prefix)-2), cmd[pid] return " " prefix } function print_children (pid, prefix, child) { printf "%6i %6i %7s %s %s %s\\_ %s\n", \ pid, father[pid], start[pid], tty[pid], time[pid], \ substr(prefix, 1, length(prefix)-2), cmd[pid] if (! nchild[pid]) return for (child = 0; child < nchild[pid] - 1; child ++) print_children(children[pid, child], prefix " | ") print_children(children[pid, child], prefix " ") } END { if (! whichpid) whichpid = 1 if (! cmd[whichpid]) exit if (father[whichpid]) prefix = " " print_parents(father[whichpid]) else prefix = " " print_children(whichpid, prefix) }' whichpid=$1 --J/dobhs11T7y2rNN-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message