Notes on operating online replacement files on Linux systems

  
                

If you don't understand the Linux system to replace files, it is easy to cause text file busy error prompts at cp, so it is very important to master the Linux system to replace files on the line. Let's go.

Oh Eng has recently found that many do not know the gist replace the file online operations. So the Xiaobian of the System Home has been sorted out so that you can understand.

When replacing a file that is running a process online (including binary, dynamic libraries, resource files that need to be read, etc.). Avoid using cp/scp operations. Instead, you need to use mv/rsync instead.

Cause: cp truncates the source file and writes the new content. That is to say, the process that is opening this file can immediately perceive the modification. Modifying the contents of a file is likely to cause program logic errors or even crashes. And mv is the mark & ​​delete the old file, and then put a new file with the same name in the past. That is to say, the old file and the new file are actually two different files (inode is different), just the same name. The process of opening old files will not be affected. If the process uses mmap to open a file (such as loading so), if the target file is overwritten with cp and the length is smaller. Then when reading the address of the difference part (which actually does not exist in the new file), it will cause the SIGBUS signal. Cause the process to crash.

As for the executable itself. It is not afraid that cp will cause a crash. . Because cp will report & text; text file busy“. At the root of the cp can not. At this time, you should also use the mv class operation. Restart the process after the replacement is complete. The new executable is executed.

The above is the introduction of the Linux system online replacement file notes, if you prompt text file busy in cp, it may be an operational error, should be changed to mv class operation.

Copyright © Windows knowledge All Rights Reserved