Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Dec 2008 02:20:03 GMT
From:      Nate Eldredge <neldredge@math.ucsd.edu>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/102357: tcsh(1)/csh(1) jobs control: sometimes 'fg' command doesn't capture back the background process
Message-ID:  <200812040220.mB42K3cW081473@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/102357; it has been noted by GNATS.

From: Nate Eldredge <neldredge@math.ucsd.edu>
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812040220.mB42K3cW081473>