Run-Time Function: Registers the function to be called if an interrupt signal occurs.
Module: USE DFLIB
Syntax
Results:
The result is of type INTEGER(4). The result is a positive integer if successful; otherwise, -1 (SIG$ERR).
SIGNALQQ installs the function func as the handler for a signal of the type specified by sig. If you do not install a handler, the system by default terminates the program with exit code 3 when an interrupt signal occurs.
The argument func is the name of a function and must be declared with either the EXTERNAL or IMPLICIT statements, or have an explicit interface. A function described in an INTERFACE block is EXTERNAL by default, and does not need to be declared EXTERNAL.
When an interrupt occurs, except a SIG$FPE interrupt, the sig argument SIG$INT is passed to func, and then func is executed.
When a SIG$FPE interrupt occurs, the function func is passed two arguments: SIG$FPE and the floating-point error code (for example, FPE$ZERODIVIDE or FPE$OVERFLOW) which identifies the type of floating-point exception that occurred. The floating-point error codes begin with the prefix FPE$ and are defined in DFLIB.F90 in the \DF98\INCLUDE subdirectory. Floating-point exceptions are described and discussed in The Floating-Point Environment in the Programmer's Guide.
If func returns, the calling process resumes execution immediately after the point at which it received the interrupt signal. This is true regardless of the type of interrupt or operating mode.
Because signal-handler routines are normally called asynchronously when an interrupt occurs, it is possible that your signal-handler function will get control when a run-time operation is incomplete and in an unknown state. Therefore, do not call heap routines or any routine that uses the heap routines (for example, I/O routines, ALLOCATE, and DEALLOCATE).
To test your signal handler routine you can generate interrupt signals by calling RAISEQQ, which causes your program either to branch to the signal handlers set with SIGNALQQ, or to perform the system default behavior if SIGNALQQ has set no signal handler.
The example below demonstrates a signal handler for SIG$ABORT. A sample signal handler for SIG$FPE is given in Handling Floating-Point Exceptions in the Programmer's Guide.
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also: RAISEQQ, SIGNAL, KILL, GETEXCEPTIONPTRSQQ
Example
! This program shows a signal handler for
! SIG$ABORT
USE DFLIB
INTERFACE
FUNCTION h_abort (signum)
!DEC$ATTRIBUTES C :: h_abort
INTEGER(4) h_abort
INTEGER(2) signum
END FUNCTION
END INTERFACE
INTEGER(2) i2ret
INTEGER(4) i4ret
i4ret = SIGNALQQ(SIG$ABORT, h_abort)
WRITE(*,*) 'Set signal handler. Return = ', i4ret
i2ret = RAISEQQ(SIG$ABORT)
WRITE(*,*) 'Raised signal. Return = ', i2ret
END
!
! Signal handler routine
!
INTEGER(4) FUNCTION h_abort (signum)
!DEC$ATTRIBUTES C :: h_abort
INTEGER(2) signum
WRITE(*,*) 'In signal handler for SIG$ABORT'
WRITE(*,*) 'signum = ', signum
h_abort = 1
END