You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The implemention of isfile_strict() decides a file won't be appended into the result of open_files() if the file doesn't exist, but for container processes, we cannot just use the value returned by os.readlink() function to check the existence of the file because of the mount namespace.
Solutions
One of the solution is we can use /proc/[pid]/root/ + [value of readlink] to check the existence of a file. The doc of /proc/[pid]/root is here https://man7.org/linux/man-pages/man5/proc.5.html. But it may not be a good idea to treat it as the return value of open_files().
In order to dereference /proc/[pid]/root, we need to find the actual rootfs of a process. It seems to be no better solution to finish it, but there's still a workaround by the third field in /proc/[pid]/mountinfo. For example, the following is the content of /proc/[pid]/mountinfo of a container process:
Summary
Description
The key point is
isfile_strict()
function inopen_files()
(L2209):psutil/psutil/_pslinux.py
Lines 2183 to 2228 in 3795983
The definition of
isfile_strict()
function:psutil/psutil/_common.py
Lines 475 to 487 in 3795983
The implemention of
isfile_strict()
decides a file won't be appended into the result ofopen_files()
if the file doesn't exist, but for container processes, we cannot just use the value returned byos.readlink()
function to check the existence of the file because of the mount namespace.Solutions
One of the solution is we can use
/proc/[pid]/root/ + [value of readlink]
to check the existence of a file. The doc of/proc/[pid]/root
is here https://man7.org/linux/man-pages/man5/proc.5.html. But it may not be a good idea to treat it as the return value ofopen_files()
.In order to dereference
/proc/[pid]/root
, we need to find the actual rootfs of a process. It seems to be no better solution to finish it, but there's still a workaround by the third field in/proc/[pid]/mountinfo
. For example, the following is the content of/proc/[pid]/mountinfo
of a container process:We know the major and minor number of rootfs is
0:49
. From/proc/1/mountinfo
we find0:49
corresponds to the following:The text was updated successfully, but these errors were encountered: