As we know, when we execute an executable file, this file will be loaded into RAM.
So I'm thinking that I can rm a.exe
after ./a.exe
.
In my opinion, after executing ./a.exe
, this file has been loaded into RAM, so I should be able to remove it from the hard drive. I used an example to do a simple test:
#include <iostream>
#include <thread>
#include <chrono>
int main()
{
while (true)
{
std::cout<<"hello world"<<std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
}
return 0;
}
I compiled the code and executed it, I can see hello world
keeps poping up.
Then I remove the executable file, and hello world
still keeps poping up.
So I think I could remove an executable file while it is running.
But today I tried to do the same thing to another C++ project, and after I removing the executable file, it crashed.
Why? Which kind of reason can cause the crash?
.out
, such asa.out
. I wrote.exe
to make it clearer. – Yves Mar 30 '18 at 09:09rm
. – Yves Mar 31 '18 at 08:41