Kill a process by PID
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | pid | |||
logical, | intent(out) | :: | success | |||
logical, | intent(in), | optional | :: | force |
subroutine sys_kill_process(pid, success, force) integer, intent(in) :: pid logical, intent(out) :: success logical, intent(in), optional :: force character(len=128) :: command integer :: exitstat logical :: force_kill force_kill = .false. if (present(force)) force_kill = force if (get_os_type() == OS_WINDOWS) then if (force_kill) then write (command, '(A,I0)') 'taskkill /F /PID ', pid else write (command, '(A,I0)') 'taskkill /PID ', pid end if else if (force_kill) then write (command, '(A,I0,A)') 'kill -9 ', pid, ' 2>/dev/null' else write (command, '(A,I0,A)') 'kill ', pid, ' 2>/dev/null' end if end if call execute_command_line(command, exitstat=exitstat) success = (exitstat == 0) end subroutine sys_kill_process