Re: ctrl - C



2008-07-31, 02:10(-07), peter:
Hi All
if script A that execute script B, during its executing, i press
ctrl-c, it will stop the script A if it doesn't handle the ctrl-c. How
can i forword the ctrl-c signal from script A to script B?
[...]

Upon <Ctrl-C>, SIGINT will be sent to every process in the
foreground process group of the terminal, which will include the
shell running script A, the shell running script B and whatever
process spawned by script A and script B that are still running.

If you want only the shell running script B and its children to
be killed by the SIGINT, in script A, you can do:

trap : INT

That will run the null command upon SIGINT instead of exiting
for the shell running script A and every children of his until
they themselves do an exec.

You can also do:

killed=false
trap killed=true INT

So that you can later on do:

if "$killed"; then...

$ sh -c 'killed=false; trap killed=true INT; echo A1;
sh -c "echo B1; sleep 2; echo B2"; echo A2 $killed'
A1
B1
^CA2 true
$ sh -c 'killed=false; trap killed=true INT; echo A1;
sh -c "echo B1; sleep 2; echo B2"; echo A2 $killed'
A1
B1
B2
A2 false

--
Stéphane
.



Relevant Pages

  • (reposted) Question about CTRL-C handling in scripts
    ... I have a 'wrapper' script that sets up some environment variables and ... then executes another script, which then eventually runs a Fortran ... Then it requires a second <Ctrl-C> to exit this looping and return to ...
    (comp.unix.shell)
  • Cant ctrl-c to exit with DBI, DBD::Oracle
    ... Once my script connects to my database, ... I just can't exit when I'm done. ... use DBI; ... I'm able to interrupt the script with ctrl-c as I'd expect. ...
    (perl.dbi.users)
  • RE: Send CTRL-C to program started with WshShell.Exec method
    ... What I'm looking for is not a solution to stop the VB Script but a solution ... to stop defrag.exe in clean manner. ... >> can be stopped by pressing CTRL-C. ... It only stop when the defragmentation is finished or by pressing ...
    (microsoft.public.scripting.vbscript)
  • trap does not
    ... I'm trying to abort the execution of a scipt, ... Ctrl-C. ... So I put the 'trap' command at the beginning of the script, ...
    (comp.os.linux.misc)
  • Re: Batch Vorgang abbrechen, aber nicht =?ISO-8859-1?Q?schlie=DF?= =?ISO-8859-1?Q?en
    ... sondern nur der aktuelle Vorgang. ... Danach soll das Script ... weiterlaufen. ... Wenn du Ctrl-C drückst, fragt er "Batchvorgang abbrechen ...
    (microsoft.public.de.german.windowsxp.sonstiges)