2

First use Vim to edit a file, say /tmp/A.

Assuming that vim process is the only one that accesses /tmp/A, then use "ctrl+z" to suspend the process, and execute

fuser /tmp/A

Then you see nothing in the output.

However, if you use "less" to open that file, you could see the pid of less in the fuser output.

Is there anthing special about vim that makes this weird scenario?

4

Yes, vim does not open the file until it needs to save it. Instead, vim uses a temporary hidden swap file to save changes you make incrementally. Once you save the file (:w) it will write to the original file.

You can see that for yourself by using lsof, i.e.:

$ lsof -n -p `pidof vim`
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
[...]
vim     9695 gert    4u   REG  252,1    12288 410388 /tmp/.a.swp
[...]

This is common behaviour for editors. less just reads the file and it's of no benefit to use tricks when just opening a file for reading.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.