From owner-freebsd-bugs@FreeBSD.ORG Thu Dec 4 02:20:04 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BC34C106567A for ; Thu, 4 Dec 2008 02:20:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id AB8728FC20 for ; Thu, 4 Dec 2008 02:20:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id mB42K3Nq081474 for ; Thu, 4 Dec 2008 02:20:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id mB42K3cW081473; Thu, 4 Dec 2008 02:20:03 GMT (envelope-from gnats) Date: Thu, 4 Dec 2008 02:20:03 GMT Message-Id: <200812040220.mB42K3cW081473@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Nate Eldredge Cc: Subject: Re: bin/102357: tcsh(1)/csh(1) jobs control: sometimes 'fg' command doesn't capture back the background process X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Nate Eldredge List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Dec 2008 02:20:04 -0000 The following reply was made to PR bin/102357; it has been noted by GNATS. From: Nate Eldredge To: bug-followup@FreeBSD.org, todor.dragnev@gmail.com Cc: Subject: Re: bin/102357: tcsh(1)/csh(1) jobs control: sometimes 'fg' command doesn't capture back the background process Date: Wed, 3 Dec 2008 18:19:01 -0800 (PST) It looks like this is a "feature". csh has a notion of the "current" job. If you run 'jobs', the current job will be marked with a +. Running fg, bg, etc without arguments acts on the current job. There is code in tcsh's bg command that explicitly sets the job just backgrounded not to be the current job (calling the pclrcurr() function). If there are other jobs running, one of them becomes the current job. If no other jobs are running, as in your test case, then there will be no current job. (pcurrent is set to NULL.) Note at this point that the 'jobs' command doesn't display a + by your job. 'fg' without arguments correctly says there is no current job. 'fg %1' will do what you want, of course. I am not sure what is the point of this behavior, but it definitely seems intentional. It goes back at least as far as tcsh 6.00 circa 1995. I could imagine that some scripts may depend on it now so I think maybe it should not be changed. However, I've attached a patch that will eliminate this behavior, if you want to try it. With the patch a backgrounded current job remains current. When you run another job ('man' in your example), it becomes the current job when it is started. When it completes, it can't be the current job anymore, so, as before, tcsh looks for another job to set as the current one. The only candidate is 'tail -f', so it becomes the current job again. At this point if you run 'jobs' again you'll see the + indicator, and fg/bg will work as you expect. --- tcsh.orig/sh.proc.c 2007-10-16 09:18:39.000000000 -0700 +++ src/contrib/tcsh/sh.proc.c 2008-12-03 18:01:35.000000000 -0800 @@ -1546,8 +1546,6 @@ np->p_flags &= ~PFOREGND; } } while ((np = np->p_friends) != pp); - if (!foregnd) - pclrcurr(pp); (void) pprint(pp, foregnd ? NAME | JOBDIR : NUMBER | NAME | AMPERSAND); /* GrP run jobcmd hook if foregrounding */ -- Nate Eldredge neldredge@math.ucsd.edu