[linux-l] trap-Kommandoausführung
Axel Weiß
aweiss at informatik.hu-berlin.de
Di Jun 8 17:29:54 CEST 2004
Jens Dreger schrieb:
> Da muss man aufpassen. Sobald man ein "trap 'touch trapped' 2 3"
> gesetzt hat, reicht es, NUR Ctrl-C zu druecken, und die Datei ist
> da. Der trap wird ja fuer die aktuelle shell gesetzt:
Dann frage ich mich, warum im ersten Beispiel der Trap für die Shell
zuschlägt. Mal wird der Trap ausgeführt, mal nicht, wenn ich mit CTRL-C ein
laufendes Programm beende - abhängig von einem './' vorm Dateinamen ??
Gruß,
Axel
>
> dreger at smart:..belug/bash> trap 'touch trapped' 2 3
> dreger at smart:..belug/bash> trap
> trap -- 'touch trapped' SIGINT
> trap -- 'touch trapped' SIGQUIT
> dreger at smart:..belug/bash> ls
> dreger at smart:..belug/bash> [CTRL-C gedrueckt]
> dreger at smart:..belug/bash> ls
> trapped
>
> Das gleiche passiert auch, wenn man ./trapped nimmt:
>
> dreger at smart:..belug/bash> rm trapped
> dreger at smart:..belug/bash> trap 'touch ./trapped' 2 3
> dreger at smart:..belug/bash> trap
> trap -- 'touch ./trapped' SIGINT
> trap -- 'touch ./trapped' SIGQUIT
> dreger at smart:..belug/bash>
> dreger at smart:..belug/bash> ls
> trapped
>
> Der trap wird ausgefuehrt, wenn das signal an die shell geschickt
> wird:
>
> dreger at smart:..belug/bash> rm trapped
> dreger at smart:..belug/bash> kill -INT $$
>
> dreger at smart:..belug/bash> ls
> trapped
>
> Nicht jedoch, wenn das signal bei einem ausgefuehrten Kommando
> ankommt:
>
> dreger at smart:..belug/bash> find / -name nosuchfile &
> [1] 15384
> dreger at smart:..belug/bash> kill -INT 15384
> [1]+ Interrupt find / -name nosuchfile
> dreger at smart:..belug/bash> ls
> dreger at smart:..belug/bash>
>
> Die Loesung liegt wohl in der Formulierung [man bash]:
>
> When a simple command other than a builtin or shell function is to
> be executed, it is invoked in a separate execution environment that
> consists of the following. [...]
>
> * traps caught by the shell are reset to the values the inherited
> from the shell's parent, and traps ignored by the shell are
> ignored.
> [...]
>
> Gruss,
>
> Jens.
>
> _______________________________________________
> linux-l mailing list
> linux-l at mlists.in-berlin.de
> Die Mailingliste der BeLUG (Berliner Linux User Group)
>
> Wenn du diese Mailingliste abbestellen willst, gehe bitte auf
> https://mlists.in-berlin.de/mailman/listinfo/linux-l
> und trage dich dort bitte aus
--
Humboldt-Universität zu Berlin
Institut für Informatik
Signalverarbeitung und Mustererkennung
Dipl.-Inf. Axel Weiß
Rudower Chaussee 25
12489 Berlin-Adlershof
+49-30-2093-3050
** www.freesp.de **
Mehr Informationen über die Mailingliste linux-l