How safe is reading / copying the file to which it is added?

If events are constantly being added to the log file, how safe is it to read this file (or copy it) using another process?

+4
source share
1 answer

Unix allows you to read and write at the same time. It is completely safe to read the file while others are added to it.

Of course, it may happen that the attached act is not finished until the act of reading reaches the end of the file, then this reader will receive an incomplete version (for example, only a part of the new record at the end of the file). But technically, this is correct, because the file was really in this state while it was being read (for example, copied).

EDIT

There are more.

, , .

(rm(1), unlink(2)), . , ( , ) . , , .

, , . , rm.   , . , , , ( ).

:

, . (truncate(1), truncate(2), open(2) , append, : > filepath), . , , , , e. . . .

, ( Unix). . .

+3

Source: https://habr.com/ru/post/1685944/


All Articles