Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to replace files in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report