[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash passes changed termios to backgrounded process(es) groups?
From: |
Chet Ramey |
Subject: |
Re: bash passes changed termios to backgrounded process(es) groups? |
Date: |
Fri, 30 Aug 2024 09:25:03 -0400 |
User-agent: |
Mozilla Thunderbird |
On 8/29/24 2:17 PM, Robert Elz wrote:
Date: Thu, 29 Aug 2024 10:40:25 -0400
From: Chet Ramey <chet.ramey@case.edu>
Message-ID: <b1ae5f45-a9fe-407f-8a76-6e36e7248166@case.edu>
| It's not a big problem. You're in the background if your process group is
| not equal to the terminal's process group.
That's more or less sufficient to determine if the process is in a background
job - but being a background process simply means that the shell is not waiting
for it to complete, before doing other things.
Sure, but you have to play the percentages. In the non-job-control case,
you don't have any way to check and can't do really anything if you manage
to find out you're in the background.
If that's true then the system's definition of how tostop works is broken.
"stty tostop" means "stop the process (group) if an attempt is made to
send output to the terminal". The stop is done by sending SIGTTOU.
Setting the window size will send SIGTTOU. If you want to stop if you're
not in the foreground, that's an easy, transparent way to do it.
| Sure. But if you are restarted (and get your SIGCONT) due to the equivalent
| of a `bg', you still have to check whether you're in the foreground.
Well, kind of, the more common approach, by most applictions, is to not
bother to test, never ignore SIGTTIN/SIGTTOU, and simply go ahead and do
whatever is needed, if the process stops because of one of those, and then
is resumed as a background job, it will simply stop again when whatever
made it stop is repeated. When it is resumed in foreground, it can do
whatever is needed, and then (perhaps) be moved back to background later.
Yeah, but that's the problem here. If you're going to fetch the terminal
attributes and restore them later, you want to make sure you're in the
foreground when you do it. You don't know what the foreground process has
modified -- in this case, readline set up the terminal to do editing
input before Mail fetched the attributes. That way, even if you're in the
foreground when you finally exit and restore the terminal attributes,
they're the right ones.
The safest way to do that is to either force the stop at startup, or before
you try to fetch the terminal attributes. Don't try to ignore SIGTTIN or
SIGTTOU. Or you could fetch the attributes every time you get a SIGCONT
and trust that the shell does the right thing.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature
- Re: bash passes changed termios to backgrounded process(es) groups?, (continued)
- Re: bash passes changed termios to backgrounded process(es) groups?, Robert Elz, 2024/08/29
- Re: bash passes changed termios to backgrounded process(es) groups?, Martin D Kealey, 2024/08/29
- Re: bash passes changed termios to backgrounded process(es) groups?, Steffen Nurpmeso, 2024/08/29
- Re: bash passes changed termios to backgrounded process(es) groups?, Chet Ramey, 2024/08/30
- Re: bash passes changed termios to backgrounded process(es) groups?, Steffen Nurpmeso, 2024/08/29
- Re: bash passes changed termios to backgrounded process(es) groups?, Robert Elz, 2024/08/29
- Re: bash passes changed termios to backgrounded process(es) groups?, Steffen Nurpmeso, 2024/08/29
- Re: bash passes changed termios to backgrounded process(es) groups?,
Chet Ramey <=
- Re: bash passes changed termios to backgrounded process(es) groups?, Steffen Nurpmeso, 2024/08/30