From owner-freebsd-hackers@FreeBSD.ORG Sun Nov 18 20:45:37 2007 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DBBE016A419; Sun, 18 Nov 2007 20:45:37 +0000 (UTC) (envelope-from skip@menantico.com) Received: from vms048pub.verizon.net (vms048pub.verizon.net [206.46.252.48]) by mx1.freebsd.org (Postfix) with ESMTP id BB11E13C469; Sun, 18 Nov 2007 20:45:37 +0000 (UTC) (envelope-from skip@menantico.com) Received: from mx.menantico.com ([71.188.11.206]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JRP00BUOYZ4R8X2@vms048.mailsrvcs.net>; Sun, 18 Nov 2007 14:45:05 -0600 (CST) Date: Sun, 18 Nov 2007 15:47:44 -0500 From: Skip Ford In-reply-to: <20071118151712.GA21185@voi.aagh.net> To: "Bjoern A. Zeeb" , Robert Watson , Yuri , freebsd-hackers@FreeBSD.org Mail-followup-to: "Bjoern A. Zeeb" , Robert Watson , Yuri , freebsd-hackers@FreeBSD.org Message-id: <20071118204743.GE813@menantico.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-disposition: inline References: <1194980181.4739f355a32bc@webmail.rawbw.com> <20071114104157.D92502@fledge.watson.org> <20071114112304.GA835@menantico.com> <20071114121812.U2025@fledge.watson.org> <20071114132743.GB835@menantico.com> <20071116144356.S10677@fledge.watson.org> <20071116212342.GD835@menantico.com> <20071117215003.U53707@maildrop.int.zabbadoz.net> <20071117223910.GD813@menantico.com> <20071118151712.GA21185@voi.aagh.net> User-Agent: Mutt/1.4.2.3i Cc: Subject: Re: How to get filename of an open file descriptor X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Nov 2007 20:45:37 -0000 Thomas Hurst wrote: > * Skip Ford (skip@menantico.com) wrote: > > > It would be interesting to know for sure, though, if Solaris uses > > hardlinks and, if so, what their utility is called. > > Nope. They *do* use hardlinks in that they have 32bit wrappers in > /usr/bin etc which dispatch to the relevent architecture, but the > commands themselves are all seperate. Indeed, and each utility is quite complex as compared to what ours would be if split. I would just rename procstat(1) to pargs(1) then hardlink the others since ours are much less complex, but I'll take anything at this point. As for the procstat(1) code itself, I've found one bug and have two sugestions: 1) procstat_args() doesn't use a local variable and the buffer doesn't get cleared between calls: $ procstat -a 797 PID ARGS 797 audacious $ procstat -a 795 797 PID ARGS 795 xterm -xtsessionID 11c0a80103000118536826300000007680000 797 audacious essionID 11c0a80103000118536826300000007680000 $ Other option's functions are not similarly affected. 2) I think it should handle requests for information about pid 0 instead of requiring at least pid 1 as it currently does. Solaris suggests '/proc/*' to see all processes. If we use `ps axopid=` then it aborts on the swapper (pid 0) immediately. 3) Similarly, I think all of the sysctl(3) calls within the individual option functions (procstat_bin(), procstat_args(), etc.) should just go ahead and print the header and pid, then print any sysctl(3) error in the PID's row instead of erroring out. We're either about to finish executing anyway if that was the only pid requested, or we're moving on to another pid that has nothing to do with the previous pid. There's not really any reason to stop processing further pids. This also affects attempting to list all pids since it currently stops processing pids as soon as one doesn't exist. A global error variable could just be incremented with every call and returned at process exit, that way it'd still be meaningful for single PIDs. Since this is a per-process tool, I think it needs to complete "procstat -c `ps axopid=`" if at all possible. -- Skip