From owner-freebsd-questions@FreeBSD.ORG Tue Apr 3 20:47:58 2012 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B97DB106564A for ; Tue, 3 Apr 2012 20:47:58 +0000 (UTC) (envelope-from matthewstory@gmail.com) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id 664FC8FC14 for ; Tue, 3 Apr 2012 20:47:58 +0000 (UTC) Received: by vbmv11 with SMTP id v11so132926vbm.13 for ; Tue, 03 Apr 2012 13:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=gj2unSCVvYoIAF96F3iNYpem4G0WsQv3VvNgSPAlrAQ=; b=RiCSAP/w6o58aNrRvPf3ugUylJgECFVrISBJu2igWWxyom5R3gh865SKc/VVs29yon oNBZFoyapxzFsRYCeOTo9hzCWzPYvglRJ/oQbobweFIT2q/xY6XS78qpl4XUYyLICdXT h56kGnF/57g3ne/OFrfVeXL8VkWoLWhi98v/naVculXkvIdXRYQoGavajlw+yFuNpska xh/2wJpEcXvJP9+pCEjNHr+9zg3q2zUiGl5rY9wGXHt16jv4zKeaEsYVzIR3TvxP0i0h 1DMCNDyyzgkdLmwd103VN1hKEBkSYOXed3RR0uRDVqSxa3N3vSy1/pKJWXAOVboOJslI rJ0A== MIME-Version: 1.0 Received: by 10.52.38.167 with SMTP id h7mr5545237vdk.109.1333486077643; Tue, 03 Apr 2012 13:47:57 -0700 (PDT) Received: by 10.52.117.66 with HTTP; Tue, 3 Apr 2012 13:47:57 -0700 (PDT) In-Reply-To: References: Date: Tue, 3 Apr 2012 16:47:57 -0400 Message-ID: From: Matthew Story To: "illoai@gmail.com" Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: questions@freebsd.org Subject: Re: current pids per tty 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, 03 Apr 2012 20:47:58 -0000 On Tue, Apr 3, 2012 at 12:33 PM, illoai@gmail.com wrote: > On 3 April 2012 04:19, takCoder wrote: > > Hi Everyone, > > > > i'm trying to find out a way to list *all* the pids of which running in > the > > background of or as the parent *of the current tty* device my shell file > is > > running on.. is there a quick way to find it out as for commands like tty > > (for current tty) or whoami (for current user) or i should just grep and > > sed the output of commands like w or ...? > > > > as you may know, W(1)'s output just shows the number of pts devices in > its > > tty column.. so it won't be that easy to grep them all(i'm somehow new in > > shell scripting as well).. and i need the detailed info about related > > processes; like FROM or WHAT outputs of w command.. (BTW, i'm trying to > > write a reporting per-tty shell script for my FreeBSD system..) > > > > it would be very kind of you giving me any tips or tricks on this. > > tcsh & sh both have a builtin called "jobs" (there is an executable > named /usr/bin/jobs, but . . . well run "cat /usr/bin/jobs" & see for > yourself). I dunno if that encompasses everything you want to do. > Across all TTYs, something like this would probably work: sudo fstat | awk '$5 ~ /^\/dev/ && $8 ~ /tty/ { printf "%s %s %s\n", $1, $8, $3; }' | sort -k1,2 from there, if you think you need to trace the process trees down, you can use this list of pids and ps to do the rest ... hopefully that helps > > -- > -- > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to " > freebsd-questions-unsubscribe@freebsd.org" > -- regards, matt