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

RE: Traps...



	El mail inicial era mio, y con la urgencia que tenia de usar esos
conocimientos, busque en el Web informacion ( no tengo instalada la pagina
man del comando trap en mi sistema, y encontre la siguiente página:

	 <<node41>> 
	Espero que sirva de ayuda como me sirvio a mi.

	Saludos
	Gustavo

	------------------------------

> En un reciente mensaje, he leido lo de poner traps a la ejecución de un
> programa para no conseguir acceso a una shell... ¿alguien es tan amable de
> explicarme qué es ésto, cómo funciona, con qué lenguajes puedo hacerlo, y
> algún ejemplillo?
> 
Title: trap: Trap signals
next up previous contents
Next: Tips Using Shell Commands Up: Programming the Shell Previous: set: Change Command-line Parameters

trap: Trap signals

Processes may be sent signals using either the kill command, or a control key combination such as CTRL-C. The interrupt signal (CTRL-C) usually kills the process.

Table gif taken from [6, p. 883,] shows some of the signals used in Shell Programming.

   table334
Table: Signal numbers for trap command.

The trap command typically appears as one of the first lines in the shell script. It contains the commands to be executed when a signal is detected as well as what signals to trap.

#!/bin/sh
TMPFILE=/usr/tmp/junk.$$
trap 'rm -f $TMPFILE; exit 0' 1 2 15 
.
.
.

Upon receiving signals 1, 2 or 15, $TMPFILE would be deleted and the script would terminate the shell script normally. This shows how trap may be used to clean up before exiting.

#!/bin/sh
TMPFILE=/usr/tmp/junk.$$
trap '' 0 1 2
.
.
.

The above example shows how trap may be used to ignore specific signals (0, 1 and 2).

NOTE that when the signal is received, the command currently being executed is interrupted, and execution flow continues at the next line of the script.



Claude Cantin
Sun Apr 11 02:10:52 EDT 1999

Reply to: