"Another program is currently running this file"
Right after cross-compiling a binary for Windows, I find myself unable to run it with the error mentionned above. This error persists even after closing Bash, and the file handler isn't detected by Process Explorer. As a workaround, I can copy the file anywhere else, and it will run fine.
@arcanis - I am not clear on your scenario. Are you trying to run a win32\64 PE binary within WSL? WSL currently only supports executing ELF64 binaries.
@sunilmut - In gcc/g++ in WSL (and other compilation tools), one can build a PE+ binary. If it is placed in a location that one's "normal" Windows cmd.exe (or other) can see the just-built executable, it should be able to be run. This problem is likely due to a (severe) delay between WSL recognizing a file is closed after being written to an NTFS file system, and flushing the file system data to the Windows subsystem. I've seen situations where the file is seen as "still open", or even it is completely absent (until time or a re-login occur). A disappointment.
@jamesdavidhoward -- is your output file being written to a directory under /mnt/, or to the Linux internal filesystem? (Not quite sure what you mean by "a location that one's "normal" Windows ... can see")
The file system update - think "flush & sync" - inconsistency occurs when creating, manipulating or deleting a file underneath /mnt/ - /mnt/c/Users/..., for example. When that directory is also viewed by, say, WindowsFile Explorer - even after an Explorer [Refresh] operation. It is completely unacceptable for there to be any more delay in finalizing NTFS metadata and data than would be experienced by a Windows PE+ executable manipulating a file.
The reverse is also true: a Windows PE executable manipulating a file or directory in the WSL subsystem.
SFU had no problem in this regard; why does WSL?
James D. Howard, [email protected]
@jamesdavidhoward -- could you post a specific reproducer? I'm not seeing that delay on my system. I don't work on the WSL team, but my understanding of their architecture is that it is intended to do exactly what you're asking for. (Which, I agree, is very important.)
The following command works for me, and would seem to indicate that a file written by WSL is in fact visible ~immediately from native Windows):
c:\Users\[my homedir]> bash.exe -c "gcc /mnt/c/Users/%USERNAME%/tmp.c -o /mnt/c/Users/%USERNAME%/tmp" && dir /b tmp
tmp
My "tmp.c" contained the following, for reference:
#include <stdio.h>
int main() {
printf("hi!\n");
return 0;
}
If I replace dir /b tmp with type tmp, I get a pile of ELF goo back (which I won't attempt to paste into github). If I run the gcc command in a WSL window, then (with the WSL window still open) run the dir command at a Windows shell, the file also appears immediately for me.
Are you running a third-party Windows antivirus program? Maybe one that is not aware of WSL? If I were an antivirus program, and I saw a bunch of Windows executable content appearing on the machine apparently out of nowhere, I would be scanning that stuff as aggressively as possible; locking it, possibly quarantining it, etc.
You refer to Windows Explorer a lot: Explorer is many layers of abstraction above the actual physical storage. Is it possible that you have an Explorer plugin on your machine that's misbehaving?
Experimenting with these scenarios subsequent to update to build 14372, and then lxrun /uninstall, then lxrun /install, the situation is greatly improved. The one remaining long delay is the following:
- Open bash shell,
cdto one's$HOME - Open File Explorer (I've no 3rd-party add-ins, yet, since they often screw up in Windows 10), and navigate to
%HOMEDRIVE%%HOMEPATH%\AppData\Local\lxss\home\%USERNAME% - bash: "
touch WSLfile" - Explorer: empty file appears
- Explorer: select WSLfile and [Shift Right Click] delete it
- visibly gone from Explorer
- visibly gone from
CMD.EXEshellcd'd to same place - still present in bash shell
ls... wait a couple of minutes - now gone everywhere.
Not running 3rd-party anti-virus: running Defender Not running and non-MSFT File Explorer extensions. example: do have "Scan with Defender: context menu extension...
@jamesdavidhoward - Thanks for the detailed explanation of what you're seeing. The user home directory is a VolFs mount which doesn't handle concurrent use between NT and WSL very well. For now if you want to access files from both NT and WSL I'd suggest using a DriveFs path (somewhere under one of your drive mounts /mnt/*). This is definitely something we'll be working on improving in future releases.
We have a video explaining the differences between VolFs and DriveFs as well as a blog post if you prefer that format.
Discussion ran course last year.