Signal handling in PGI Fortran

Hi all,
I am trying to capture the signal error handling such as Ctrl-C.
I tried the signal function available in PGI fortran. But I am not able to make it to work. Here is a small test code.

Program Test
Integer(4) iretw
Integer(4) flag
External Procedure


flag = 0
Do While(.true.)
iretw = Signal(SIGINT, Procedure, -1)
End Do

Stop
End

Subroutine Procedure(iretw)


Write(,) ‘Closing Programs’
Pause

Return
End

Please let me know if i need to add any include file for handling error handlers. I am assuming SIGINT is available in one of the include files.

Thanks
Venkat

Hi Venkat,

“SIGINT” isn’t declared so you’re passing in an undefined value. Instead, declare SIGINT as an integer and assign it the value of ‘2’.

Here’s my modified version:

% cat sig.f90 

Program Test
implicit none
Integer(4) iretw, SIGINT
Integer(4) flag
External Procedure
integer signal

SIGINT=2
flag = 0
iretw = Signal(SIGINT, Procedure, -1)
Do While(.true.)
End Do

End

Subroutine Procedure()
Write(*,*) 'Closing Programs'
pause
stop
Return

End subroutine
% pgf90 sig.f90
% a.out
 Closing Programs
FORTRAN PAUSE: enter <return> or <ctrl>d to continue>
FORTRAN STOP

Hope this helps,
Mat