I am trying to use system calls to get the free memory on Linux at run-time. However it seems that if the virtual memory gets very low then the code will crash because it cannot launch the system call. I found this explanation which I don’t know if it is accurate:
Do you know if there is any way to avoid this problem or check free mem at run time otherwise?.
Maybe a good idea to add to fortran intrinsics efficient mem check subroutines?
Maybe a simple solution would be instead of using a system call, just calling some external library for doing mem check without having the process “cloned” (as the link above says and hence running out of virt mem). Do you know any good library easy to use/link with for doing so to recommend?.
I feel this should be added into the intrinsics: Something like a fake allocate call that retrieves the amount of free mem.
character(132) :: ligne
open (unit=1, file="/proc/meminfo", access="sequential", status="old")
do
read(1, '(a)', end=200) ligne
print *, ligne
end do
200 close(1)
end
character(132) :: ligne
integer :: mem
open (unit=1, file="/proc/meminfo", access="sequential", status="old")
read(1, '(a)') ligne
read(1, '(a)') ligne
read(1, '(a)') ligne
print *, ligne
print *, ligne(18:24)
read(ligne(18:24), *) mem
print *, mem
close(1)
end
Yes, I am doing something like that at run-time using “call system”/“execute command line”. Problem is that when mem is scarce it crashes due to the reason given above…
OK. But then if I just open directly the file as in your example lines (with open) then it could actually work. I’ll try it. Thanks!