Check if a process exists
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | pid |
function sys_process_exists(pid) result(exists) integer, intent(in) :: pid logical :: exists character(len=128) :: command integer :: exitstat if (get_os_type() == OS_WINDOWS) then write(command, '(A,I0,A,I0,A)') 'tasklist /FI "PID eq ', pid, '" 2>nul | find "', pid, '" >nul' else write (command, '(A,I0,A)') 'kill -0 ', pid, ' 2>/dev/null' end if call execute_command_line(command, exitstat=exitstat) exists = (exitstat == 0) end function sys_process_exists