[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: why are pipeline commands (allowed to be) executed in subshells?
From: |
Philippe Cerfon |
Subject: |
Re: why are pipeline commands (allowed to be) executed in subshells? |
Date: |
Tue, 20 Dec 2022 07:41:38 +0100 |
Hey.
I tried a bit further around. As far as I can see, ssh's
RequestTTY=force simply means that it uses the remote side's tty
device.
Most cases I think, I understand why they behave as they do, but
there's one left which I cannot figure out.
I run:
ssh -t -t example.org "trap 'echo HUP>> /tmp/csingal; exit' HUP; trap
'echo INT>> /tmp/csingal; exit' INT; trap 'echo QUIT>> /tmp/csingal;
exit' QUIT; sleep 100 & while true; do sleep 60; done"
# ps -e --forest -o pid -o ppid -o pgid -o tpgid -o args
PID PPID PGID TPGID COMMAND
388060 388054 388060 388060 | \_ bash -c trap 'echo HUP>>
/tmp/csingal; exit' HUP; trap 'echo INT>> /tmp/csingal; exit' INT;
trap 'echo QUIT>> /tmp/csingal; exit' QUIT; sleep 100 & w
388061 388060 388060 388060 | \_ sleep 100
388062 388060 388060 388060 | \_ sleep 60
When I now ^C the ssh, then all processes get the INT and the sleep
100 in the "background" gets an additional HUP (which actually kills
it). Not sure why it gets both and the iNT doesn't kill it, but at
least it's dead.
As far as I understand, all three processes are actually in the same
terminal foreground process group, because their PGID is TPGID, right?
And I guess that's generally the case for scripts or -c, when there is
no interactive shell? Also -i didn't seem to change that.
So I tried to make it behave like an interactive shell, where ^C
wouldn't kill the sleep 100 in the background, which I did by adding
set -m in the command:
$ ssh -t -t example.org "set -m; trap 'echo HUP>> /tmp/csingal; exit'
HUP; trap 'echo INT>> /tmp/csingal; exit' INT; trap 'echo QUIT>>
/tmp/csingal; exit' QUIT; sleep 100 & while true; do sleep 60; done"
# ps -e --forest -o pid -o ppid -o pgid -o tpgid -o args
PID PPID PGID TPGID COMMAND
388461 388455 388461 388463 \_ bash -c set -m; trap 'echo
HUP>> /tmp/csingal; exit' HUP; trap 'echo INT>> /tmp/csingal; exit'
INT; trap 'echo QUIT>> /tmp/csingal; exit' QUIT; sleep
388462 388461 388462 388463 \_ sleep 100
388463 388461 388463 388463 \_ sleep 60
looks good, the sleep 100's PGID differs from the TPGID
^C lets the sleep 60 receive a INT, expected. The sleep 100 sees
nothing (expected) but gets a PPID of 1 and a TPGID of -1 and
continues to run (also expected). Bash gets a SIGCHILD, also expected,
but then exits, which I don't understand. Shouldn't it just start the
next seep 60?
Thanks,
Philippe
- Re: why are pipeline commands (allowed to be) executed in subshells?, (continued)
- Re: why are pipeline commands (allowed to be) executed in subshells?, Philippe Cerfon, 2022/12/12
- Re: why are pipeline commands (allowed to be) executed in subshells?, Philippe Cerfon, 2022/12/12
- Re: why are pipeline commands (allowed to be) executed in subshells?, Greg Wooledge, 2022/12/12
- Re: why are pipeline commands (allowed to be) executed in subshells?, Philippe Cerfon, 2022/12/13
- Re: why are pipeline commands (allowed to be) executed in subshells?, Greg Wooledge, 2022/12/13
- Re: why are pipeline commands (allowed to be) executed in subshells?, Philippe Cerfon, 2022/12/13
- Re: why are pipeline commands (allowed to be) executed in subshells?, Greg Wooledge, 2022/12/13
- Re: why are pipeline commands (allowed to be) executed in subshells?, Philippe Cerfon, 2022/12/13
- Re: why are pipeline commands (allowed to be) executed in subshells?, Chet Ramey, 2022/12/13
- Re: why are pipeline commands (allowed to be) executed in subshells?, Philippe Cerfon, 2022/12/13
- Re: why are pipeline commands (allowed to be) executed in subshells?,
Philippe Cerfon <=
- Re: why are pipeline commands (allowed to be) executed in subshells?, Chet Ramey, 2022/12/21
- Re: why are pipeline commands (allowed to be) executed in subshells?, Philippe Cerfon, 2022/12/21
- Re: why are pipeline commands (allowed to be) executed in subshells?, Chet Ramey, 2022/12/22
Re: why are pipeline commands (allowed to be) executed in subshells?, Chet Ramey, 2022/12/13