Forum > Unix

Close/reopen text file

<< < (3/3)


--- Quote from: Kays on January 10, 2022, 05:50:49 pm ---Inotify does not work (reliably) on pseudo file systems such as procfs(5) or devfs/devtmpfs.

--- End quote ---

True, but what I'm trying to do is get the writer "doing the right thing", or at least "doing the best under the circumstances".

--- Quote ---Files are only really deleted if they are not opened (confer output of lsof(8)) and their (hardlink) reference count hits zero. Similarly, as long as someone somewhere (e.g. another process) holds a valid FD to stdout, this stdout is not closed/“deleted”.

--- End quote ---

True, and that's one reason why unix doctrine has settled on a comparatively complex rename-and-copy sequence to handle reopening a file when a backup is to be saved. But I'd prefer not to rely on it when a Pascal-style Rewrite() is used, since this implies that a file is truncated and (potentially) that the space is reused.

So what I've coded for the time being is:

* When the instrument has generated data the file or pipe/FIFO/socket is closed.

* If it's a pipe/FIFO/socket it's reopened promptly, since this gives both ends the best chance of sorting things out.

* If it's a regular file it's not reopened until the next instrument run in case that causes data to be lost.

The interpretation of "promptly" will no doubt need to be adjusted, depending on the reliability of the inotify API and/or file timestamps etc.

As I've said though, this is really an attempt to "do the right thing" under different circumstances.



--- Quote from: MarkMLl on January 10, 2022, 09:46:03 pm ---[…] Rewrite()
--- End quote ---
There is append (in Extended Pascal, ISO 10206, known as extend). For character devices such as your terminal it’s evidently irrelevant, I think,.


[0] Message Index

[*] Previous page

Go to full version