From owner-freebsd-questions@FreeBSD.ORG Wed Apr 4 13:18:59 2012 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 B5754106564A for ; Wed, 4 Apr 2012 13:18:59 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) by mx1.freebsd.org (Postfix) with ESMTP id 32DF28FC14 for ; Wed, 4 Apr 2012 13:18:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id q34DINFk090571; Wed, 4 Apr 2012 23:18:24 +1000 (EST) (envelope-from smithi@nimnet.asn.au) Date: Wed, 4 Apr 2012 23:18:23 +1000 (EST) From: Ian Smith To: perryh@pluto.rain.com In-Reply-To: <20120404120037.B3B8110657DE@hub.freebsd.org> Message-ID: <20120404230032.B2060@sola.nimnet.asn.au> References: <20120404120037.B3B8110657DE@hub.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: illoai@gmail.com, freebsd-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: Wed, 04 Apr 2012 13:18:59 -0000 In freebsd-questions Digest, Vol 409, Issue 5, Message: 3 On Wed, 04 Apr 2012 08:03:11 -0700, perryh@pluto.rain.com wrote: > "illoai@gmail.com" wrote: > > > (there is an executable named /usr/bin/jobs, but . . . > > well run "cat /usr/bin/jobs" & see for yourself). > > Whoa! Does /usr/bin/jobs even work? > > $ cat /usr/bin/jobs > #!/bin/sh > # $FreeBSD: src/usr.bin/alias/generic.sh,v 1.2.10.1.4.1 2010/06/14 02:09:06 kensmith Exp $ > # This file is in the public domain. > builtin ${0##*/} ${1+"$@"} > > It looks as if generic.sh intends to have the same effect as the > builtin matching the name under which the script is run, but at > least for "jobs" I don't think it will DTRT because it will run > in the wrong context: > > * The builtin "jobs" command will report all background jobs known > to the shell in which it is issued. > > * Because it is a shebang script, running /usr/bin/jobs will cause > the shell in which it is run to fork/exec an instance of /bin/sh, > and that instance will execute the /usr/bin/jobs script, thus it > will will be the new /bin/sh instance that executes _its_ builtin > "jobs" command -- reporting nothing, since _that_ instance has not > put anything into the background (and has no knowledge of what-all > its parent shell may have put in the background). Quite so: t23# jobs -l t23# sleep 60 & [1] 86793 t23# jobs -l [1] + 86793 Running sleep 60 t23# /usr/bin/jobs -l t23# jobs -l [1] + 86793 Running sleep 60 t23# sh # jobs -l # sleep 60 & # jobs -l [1] + 86819 Running sleep 60 # /usr/bin/jobs -l # jobs -l [1] + 86819 Running sleep 60 # exit t23# jobs -l [1] + 86793 Running sleep 60 t23# jobs -l [1] 86793 Done sleep 60 t23# jobs -l t23# cheers, Ian