help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Difference for SIGINT between subshells and external program


From: Peng Yu
Subject: [Help-bash] Difference for SIGINT between subshells and external programs?
Date: Thu, 6 Dec 2018 22:22:50 -0600

Hi,

       Non-builtin commands run by bash have signal handlers set to the values
       inherited  by  the  shell  from its parent.  When job control is not in
       effect, asynchronous commands ignore SIGINT and SIGQUIT in addition  to
       these  inherited handlers.  Commands run as a result of command substi-
       tution ignore the keyboard-generated job control signals SIGTTIN, SIGT-
       TOU, and SIGTSTP.

I am trying to understand what "asynchronous commands" refer to in the
above text. Does it just refer to external commands run with "&" at
the end, and subshell is not included?

When I type ctrl-C after main.sh runs, the sleep processes still keep
running. So it matches the manual description.

ctrl-C triggers the traps in the subshells in main_subshell.sh. So
"asynchronous commands" do not apply to them? These subshells still
receive the SIGINT signals?

Thanks.

$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

for i in {1..3}
do
    sleep 100 &
done
wait
$ ./main.sh
^C
$ ps -t "$(tty | cut -f 3 -d /)" |grep sleep
98683 ttys059    0:00.01 sleep 100
98684 ttys059    0:00.00 sleep 100
98685 ttys059    0:00.00 sleep 100
98699 ttys059    0:00.01 grep --color sleep
$ cat main_subshell.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

for i in {1..3}
do
    (
        trap 'echo SIGINT $BASHPID' SIGINT
        sleep 100
    ) &
done
wait
$ ./main_subshell.sh
^CSIGINT 99371
SIGINT 99369
SIGINT 99370




-- 
Regards,
Peng



reply via email to

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