get_status_entry Function

private function get_status_entry(status_entry) result(val)

Try to read an integer from /proc/self/status. Returns negative if not possible to open file.

Arguments

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

Return Value integer(kind=int64)


Contents

Source Code


Source Code

  integer(int64) function get_status_entry(status_entry) result(val)
    implicit none
    integer, intent(in) :: status_entry
    character(len=:), allocatable :: string
    integer :: unit, i, err
    open(action = "read", file = '/proc/self/status', newunit = unit, iostat = err)
    if (err /= 0) then
       val = -1
       return
    end if

    allocate(character(len=60)::string)
    do i = 1, status_entry
       read(unit, '(A)') string
    end do
    close(unit)

    i = scan(string, ":")
    string = string(i+1:)
    i = scan(string, "k")
    read(string(:i-1), *) val
  end function get_status_entry