Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to replace files in Linux

Shulou Source: shulou.com Published: 2022-06-01 18:02:35 09月19日 Update

This article introduces you how to replace the file in Linux, the content is very detailed, interested friends can refer to, hope to be helpful to you.

When replacing a running process file online (including binaries, dynamic libraries, resource files that need to be read, etc.). Cp/scp operations should be avoided. Instead, you need to use mv/rsync instead.

Reason: cp truncates the source file and writes new content. That is, the process that is opening the file can perceive the change immediately. Modifying the contents of the file is likely to cause program logic errors or even crashes. On the other hand, mv marks "delete" the old file, and then puts a new file with the same name in the past. In other words, the old file and the new file are actually two different files (inode is different), but the name is the same. 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 becomes smaller. Then reading the address of the difference (which no longer exists in the new file) will result in a SIGBUS signal. Cause the process to crash.

As for the executable itself. I am not afraid that cp will lead to collapse. Because "text file busy" will be reported when cp. Not cp at all. You should also use the mv class operation at this time. Restart the process after the replacement is complete. What is executed is the new executable.

On how to replace files in Linux to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: File process content different that is more help yes two binary signal but interest dynamic reason just name address Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MySQL Xiaomi Huawei OPPO Reno