I want the debugger (Gdb) attached to my Fortran program to stop under some programmed circumstances. In C/C++ this is easily possible: Set breakpoint in C or C++ code programmatically for gdb on Linux
How to raise such a signal in Fortran?
Just call the same C system function as in the linked answer
use iso_c_binding, only: c_int
implicit none
interface
function raise(sig) bind(C, name="raise")
use iso_c_binding, only: c_int
integer(c_int) :: raise
integer(c_int), value :: sig
end function
end interface
integer(c_int), parameter :: SIGINT = 2
print *, raise(SIGINT)
end
It is probably not easy to avoid entering the SIGINT integer value manually. Consult your signal.h
or man raise
. The value 2 is for POSIX. On POSIX systems you can also use SIGTRAP = 5
.