giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.1k stars 1.37k forks source link

[Windows] - psutil does not report the correct path via `Process.exe()` if a mounted volume is in the path. #2180

Open mratzenb opened 1 year ago

mratzenb commented 1 year ago

Summary

Description

psutil.Process.exe() is not reporting the correct path to a process.

The situation is the following: There are multiple processes running in C:\test\my-program\tomcat\bin\tomcat.exe. Moreover, there are multiple versions of my-program (e.g. my-program1.0, my-program1.1, ...). Additionally, test is a mounted volume and provides the following information:

 Directory of C:\
04/12/2022  07:04 PM    <DIR>               home
03/23/2022  01:50 PM    <JUNCTION>          test [\??\Volume{e4a9240d-9878-4c6c-8594-00fea2f7af11}\]
11/16/2022  02:02 PM    <DIR>               Program Files
04/12/2022  03:30 PM    <DIR>               Program Files (x86)
...

In my script, I am checking if processes of my-program are running. For that, I am interested in the PID and the location of the Process (psutil.Process.exe()). Gathering this information is done via psutil.process_iter(). The processes are listed correctly (PID). However, the problem is psutil.Process.exe().

When calling psutil.Process.exe() I would expect, that the returned path to the executable is C:\test\my-program1.0\tomcat\bin\tomcat.exe, which it is if test is not a mounted volume. However, if test is a mounted volume, it returns \my-program1.0\tomcat\bin\tomcat.exe. Meaning that the part C:\test is missing.

I guess this problem is somewhat related to #775, but might be slightly different.

Additional Info on the Mounted Volume

According to Windows, the drive is of Type Mounted Volume. However, the type switches to Local Disk if I look at the properties of the Volume. The File System inside the Volume is NTFS.

lijm1206 commented 1 year ago

ImportError: DLL load failed while importing _psutil_windows: 找不到指定的模块。