Unix behavior with two different processes containing a descriptor in one file and one process deleting a file

I am new to Unix. I have two processes containing descriptors (file descriptors) in one file on disk.

Let the processes be A, B and the sample.txt file say

Process A is the producer (writes data to the disk file), and process B is the consumer (reads from the disk file).

Process A reached the point at which it closed the file descriptor (descriptor) in the sample.txt disk file, deleted the file from the disk and opened a new file with the same name as “sample.txt” and began writing to the new file. Meanwhile, process B still has an old descriptor pointing to the old file that was deleted by process A.

Now, what happens when process B tries to read the file using the old descriptor and will it still be able to fully read the old sample.txt file to the end?

Unix guru, please shed some light on this. Any pointers to Unix kernel documents are much appreciated.

+3
source share
1 answer

The kernel supports reference counting for each open file. The second process (B) will be read from the source file, which will not be deleted from the disk until this second process completes the file descriptor, although no other processes can open this old version of the file.

Change 0:

- inode, ( ). , : open(2) ( , ). , .. inode , .

. A , , inode , open() -count. inode - , B close(2).

+2

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


All Articles