2

This is a follow up to this question: Why doesn't vim always give me the option to delete a swap file?

My laptop died with some Vim sessions open. These were all files I had already saved, so I don't need the swap files, but the "Delete" option isn't present when I edit some of them. As described in the question above, Vim thinks the previous process is still running:

Found a swap file by the name "~/.vim/tmp//%home%dominickpastore%research%codegen%rabbitmq.c.swp"
          owned by: dominickpastore   dated: Tue May 12 13:56:53 2020
         file name: ~dominickpastore/research/codegen/rabbitmq.c
          modified: no
         user name: dominickpastore   host name: carbon
        process ID: 8903 (still running)
While opening file "rabbitmq.c"
             dated: Tue May 12 13:56:49 2020

The thing is, my laptop was fully dead, so I know for a fact that the previous process is not still running! And just to be sure, I checked if there is another process with that PID, and there is not.

Interestingly, it only did this for 2 of 5 files I had open (all in different instances of Vim). It properly recognized the other 3 as gone.

How does Vim determine if the previous process is still running? Why is it sometimes mistaken?

  • 1
    Process IDs are continuously recycled, and especially on Linux, processes come and go, often very quickly; the fact that there's no such ID when you looked does not mean that this also was the case when Vim checked. – Ingo Karkat May 15 '20 at 07:32
  • 2
    @IngoKarkat I can't rule that out, but this wasn't a one-off check. I checked several times while trying to figure it out. It never appears in ps -f -p <pid> and always shows as still running in Vim, until I delete the swapfile. I've even checked while the new Vim instance was still running in case the new instance happened to have the same PID. – Dominick Pastore May 15 '20 at 13:44
  • 1
    It's possible that 8903 is now a thread of a process, rather than a PID. Vim uses kill -0 8903 to check whether a process is alive (you can use that command line to see if your shell agrees.) See this question for an example of listing thread ids and napping them back to PIDs. – filbranden May 17 '20 at 16:55

0 Answers0