sys_process_exists Function

public function sys_process_exists(pid) result(exists)

Check if a process exists

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: pid

Return Value logical


Source Code

    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