Can I replace a running program in Linux-general Linux technology-Linux programming and kernel information? For more information, see below. Today, a friend asked "Can I replace a running program in Linux ?", In the past, I vaguely remembered that it was okay in Linux (but not in Windows), So I casually replied "OK ". Result A friend sent an execution result: (test is running)
# Cp test2 test
Cp: cannot create regular file 'test': Text file busy
It seems that the program is occupied and cannot be overwritten. So I did a few more experiments:
(1) first rm deletes the running test, and then cp test2 test has no error.
(2) Change the name of the mv to the running test, and then cp test2 test is normal.
I checked the information and analyzed it. I found a satisfactory explanation. Cp does not change the inode of the target file. In fact, its implementation is as follows: