[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to forbidden SIGINT be propagated from the parent sc
From: |
Peng Yu |
Subject: |
Re: [Help-bash] How to forbidden SIGINT be propagated from the parent script to the child script? |
Date: |
Fri, 29 May 2015 11:20:13 -0500 |
On Fri, May 29, 2015 at 10:03 AM, Greg Wooledge <address@hidden> wrote:
> On Fri, May 29, 2015 at 09:48:05AM -0500, Peng Yu wrote:
>> Is there a way to make any scripts (any their child scripts) called by
>> the main script not responsive to Ctrl-C?
>
> The obvious way is to ignore SIGINT:
>
> trap '' INT
I works for this test case 1 but not test case 2. Do you know why?
What is the difference in case 2?
## case 1
==> main.sh <==
#!/usr/bin/env bash
trap '' SIGINT
echo "Start $0:$(ps -p $$ -o pgid=):$$"
./script.sh
==> script.sh <==
#!/usr/bin/env bash
trap "echo in $0 SIGINT" SIGINT
echo "Start $0:$(ps -p $$ -o pgid=):$$"
sleep 10 &
wait
echo "Finish $0:$$"
##case 2
==> main.sh <==
#!/usr/bin/env bash
trap '' SIGINT
echo "Start $0:$(ps -p $$ -o pgid=):$$"
./script.sh
==> script.sh <==
#!/usr/bin/env bash
R --slave --no-save --no-restore --no-init-file <<EOF
for(i in seq(1000)) {
x=rownames(installed.packages())
}
if(!'base' %in% x) {
print('xxx')
quit(status=1)
}
EOF
if [ $? -ne 0 ]
then
echo "R package base has not been installed." >&2
fi
$ ./main.sh
Start ./main.sh:19364:19364
^C
Execution halted
R package base has not been installed.
> The less obvious way is to map the terminal driver's intr character to
> something other than DEL (System V) or CTRL-C (BSD). For example, to
> undefine it completely:
>
> stty intr ^-
>
> Then CTRL-C (or DEL) becomes just another generic character. (Debian's
> stty also accepts undef instead of ^- but ^- appears to be the more
> common/portable way.)
>
> Of course, none of this prevents your script's child processes (once
> you've run them) from returning intr or SIGINT to their standard settings.
--
Regards,
Peng