Intel® Fortran Compiler 18.0 Developer Guide and Reference

SIGNALQQ

Portability Function: Registers the function to be called if an interrupt signal occurs.

Module

USE IFPORT

result = SIGNALQQ (sig,func)

sig

(Input) INTEGER(2). Interrupt type. One of the following constants, defined in IFPORT.F90:

  • SIG$ABORT - Abnormal termination

  • SIG$FPE - Floating-point error

  • SIG$ILL - Illegal instruction

  • SIG$INT - CTRL+CSIGNAL

  • SIG$SEGV - Illegal storage access

  • SIG$TERM - Termination request

func

(Input) Function to be executed on interrupt. It must be declared EXTERNAL.

Results

The result type is INTEGER(4) on IA-32 architecture; INTEGER(8) on Intel® 64 architecture. 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.

NOTE

All signal-handler functions must be declared with the directive !DIR$ ATTRIBUTES C.

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 IFPORT.F90.

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 shows a signal handler for SIG$ABORT.

Example


 !  This program shows a signal handler for
 !  SIG$ABORT
 USE IFPORT
 INTERFACE
   FUNCTION h_abort (signum)
     !DIR$ 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)
   !DIR$ ATTRIBUTES C :: h_abort
   INTEGER(2) signum
   WRITE(*,*) 'In signal handler for SIG$ABORT'
   WRITE(*,*) 'signum = ', signum
   h_abort = 1
 END

See Also