help-bash
[Top][All Lists]
Advanced

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

Re: why are pipeline commands (allowed to be) executed in subshells?


From: Greg Wooledge
Subject: Re: why are pipeline commands (allowed to be) executed in subshells?
Date: Tue, 13 Dec 2022 08:06:38 -0500

On Tue, Dec 13, 2022 at 01:45:12PM +0100, Philippe Cerfon wrote:
> On Tue, Dec 13, 2022 at 4:49 AM Greg Wooledge <greg@wooledge.org> wrote:
> > The shell NEVER "passes on" the signal to its child processes.
> 
> > In this example, I didn't include a trap.  But doing so makes no
> > difference in this case.  Go ahead and try it both ways, and you'll see
> > the same behavior.
> 
> Well that's clear now for the case with wait... and I also understand
> the one without wait and with HUP as signal.
> 
> But as written in two mails before, INT seems to be "passed on"
> immediately to the child sleep (which runs in the foreground there).

This is false.

Do you have an example that reproduces your claim?  With or without an INT
trap?  Is ssh still involved?  Does the problem reproduce if ssh is
removed from the picture?

Here's one with an INT trap, and without ssh:

unicorn:~$ cat foo
#!/bin/bash
trap 'echo received INT' INT
sleep 1000 &
echo "Shell process $$ awaiting sleep process $!"
wait $!
unicorn:~$ ./foo
Shell process 981631 awaiting sleep process 981632
received INT
unicorn:~$ ps
    PID TTY          TIME CMD
   1038 pts/1    00:00:00 bash
 981632 pts/1    00:00:00 sleep
 981638 pts/1    00:00:00 ps

As before, the INT was sent from another terminal window, using
 "kill -INT 981631".

As you can see, the sleep process survives.



reply via email to

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