help-bash
[Top][All Lists]
Advanced

[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: Eduardo A . Bustamante López
Subject: Re: [Help-bash] How to forbidden SIGINT be propagated from the parent script to the child script?
Date: Fri, 29 May 2015 11:11:38 -0500
User-agent: Mutt/1.5.23 (2014-03-12)

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?

If I understand you correctly, you want these to ignore Ctrl-C.

There are some ways:

1. trap "" INT
2. put them in background: script1 & script2 & wait

For 1:

By ignoring the SIGINT signal with ''trap "" INT'' in the parent script, all
the children will inherit the ignore. So you can do something like this:

# parent script
( trap "" INT
  script1 # these will now ignore SIGINT
  script2 # ...
  )

For 2:

If you put your children in background, they'll operate in a different process
group (if you have set -o monitor enabled), so they will not receive the
signals sent to the foreground group. When monitor mode is not enabled, bash
will just ignore the INT signal before running the child commands, to
work-around this.

-- 
Eduardo Bustamante
https://dualbus.me/



reply via email to

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