Try to read an integer from /proc/self/status. Returns negative if not possible to open file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | status_entry |
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