help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] backgrounding a process sends it into a tailspin


From: Chet Ramey
Subject: Re: [Help-bash] backgrounding a process sends it into a tailspin
Date: Tue, 11 Sep 2012 19:14:52 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:14.0) Gecko/20120713 Thunderbird/14.0

On 9/7/12 8:46 PM, Cook, Rich wrote:
> Hello, 
> I have built and installed gnuplot and wrapped it in a bash script.  The 
> script simply makes a usage entry in a database, calls gnuplot, then notes 
> that it exits.  I'm including the script below.  
> 
> When the user runs this script and puts it into the background, gnuplot 
> immediately starts taking up 100% of a CPU, spinning in readline.  This only 
> happens when gnuplot is wrapped in this way, not when it's called directly.  
> I would like to avoid this behavior, obviously, but I would also like to 
> continue using a wrapper script.  What is it about being called from a script 
> that is causing this odd behavior on gnuplot's part?  

I haven't looked at this at all, but it seems fairly clear that the problem
has to do with process groups and access to the terminal's foreground
process group.  gnuplot, not being used to running in the background,
doesn't have anything to ensure that it's in the right pgrp before
attempting to use readline to read from the terminal.

The signal that gnuplot gets is most likely SIGTTIN.  If it's not, ignore
the rest of this.

Starting the script in the background means that it will not be in the same
process group as its controlling terminal, which will result in SIGTTIN
every time the process tries to read from the terminal.

The non-job-control shell started to run the script getting in the middle
between the interactive shell running the script in the background and
gnuplot is complicating things, but probably not really the problem.  It
receives the SIGTTIN as well, but should have the disposition set to
SIG_DFL and get suspended.

Readline catches SIGTTIN so it can clean up the terminal attributes it
modifies.  It cleans up, ending with a call to tcsetattr from
rl_deprep_terminal, restores the old signal handler, and unblocks the
signal, letting it through to the application.  I'm not sure what gnuplot
does with it then, but I suspect it's catching it somehow and calling
readline again.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]