@@ -43,6 +43,13 @@ logical(c_bool) function process_system_kill(pid) bind(C, name='process_kill')
4343 implicit none
4444 integer (process_ID), intent (in ), value :: pid
4545 end function process_system_kill
46+
47+ logical (c_bool) function process_system_send_signal(pid, signal) bind(C, name= ' process_send_signal' )
48+ import c_bool, process_ID
49+ implicit none
50+ integer (process_ID), intent (in ), value :: pid
51+ integer , intent (in ), value :: signal
52+ end function process_system_send_signal
4653
4754 ! System implementation of a wait function
4855 subroutine process_wait (seconds ) bind(C,name= ' process_wait' )
@@ -473,6 +480,40 @@ module subroutine process_kill(process, success)
473480 end if
474481
475482 end subroutine process_kill
483+
484+ ! Send POSIX signal to a process
485+ module subroutine process_send_signal (process , signal , success )
486+ class(process_type), intent (inout ) :: process
487+ ! Signal number
488+ integer , intent (in ) :: signal
489+ ! Return a boolean flag for successful operation
490+ logical , intent (out ) :: success
491+
492+ integer (c_int) :: exit_code
493+ logical (c_bool) :: running
494+
495+ success = .true.
496+
497+ ! No need to
498+ if (process% completed) return
499+ if (process% id == FORKED_PROCESS) return
500+
501+ success = logical (process_system_send_signal(process% id, signal))
502+
503+ if (success) then
504+
505+ call process_query_status(process% id, wait= C_FALSE, is_running= running, exit_code= exit_code)
506+ process% completed = .not. running
507+
508+ if (process% completed) then
509+ ! Process completed, may have returned an error code
510+ process% exit_code = exit_code
511+ call save_completed_state(process,delete_files= .true. )
512+ end if
513+
514+ end if
515+
516+ end subroutine process_send_signal
476517
477518 subroutine save_completed_state (process ,delete_files )
478519 class(process_type), intent (inout ) :: process
0 commit comments