[UP]


Manual Reference Pages  - system_signal (3)

NAME

system_signal(3f) - [M_system:SIGNALS] install a signal handler (LICENSE:PD)

CONTENTS

Synopsis
Description
Example
Author
License

SYNOPSIS

subroutine system_signal(sig,handler)

       integer,intent(in) :: sig
       interface
         subroutine handler(signum)
         integer :: signum
         end subroutine handler
       end interface
       optional :: handler

DESCRIPTION

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.]

EXAMPLE

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

AUTHOR

Somajit Dey

LICENSE

Public Domain


system_signal (3) March 11, 2021
Generated by manServer 1.08 from eb40965d-ae6b-4c9f-a815-5fa46515866c using man macros.