system_signal(3f) - [M_system:SIGNALS] install a signal handler (LICENSE:PD)
Synopsis
Description
Examples
Author
License
subroutine system_signal(sig,handler)
integer,intent(in) :: sig interface subroutine handler(signum) integer :: signum end subroutine handler end interface optional :: handler
Calling system_signal(NUMBER, HANDLER) causes user-defined subroutine HANDLER to be executed when the signal NUMBER is caught. The same subroutine HANDLER maybe installed to handle different signals. HANDLER takes only one integer argument which is assigned the signal number that is caught. See sample program below for illustration.Calling system_signal(NUMBER) installs a do-nothing handler. This is not equivalent to ignoring the signal NUMBER though, because the signal can still interrupt any sleep or idle-wait.
Note that the signals SIGKILL and SIGSTOP cannot be handled this way.
[Compare signal(2) and the GNU extension signal in gfortran.]
Sample program:
program demo_system_signal use M_system, only : system_signal implicit none logical :: loop=.true. integer, parameter :: SIGINT=2,SIGQUIT=3 call system_signal(SIGINT,exitloop) call system_signal(SIGQUIT,quit) write(*,*)Starting infinite loop. Press Ctrl+C to exit. do while(loop) enddo write(*,*)Reporting from outside the infinite loop. write(*,*)Starting another loop. Do Ctrl+\ anytime to quit. loop=.true. call system_signal(2) write(*,*)& & Just installed do-nothing handler for SIGINT. Try Ctrl+C to test. do while(loop) enddo write(*,*)You should never see this line when running this demo.contains
subroutine exitloop(signum) integer :: signum write(*,*)Caught SIGINT. Exiting infinite loop. loop=.false. end subroutine exitloop
subroutine quit(signum) integer :: signum STOP Caught SIGQUIT. Stopping demo. end subroutine quit end program demo_system_signal
Somajit Dey
Public Domain
Nemo Release 3.1 | system_signal (3m_system) | March 07, 2025 |