0

I've written a script that should continuously check whether a file has increased in size or not. I tried simply linking to a file which I can update from another desktop, but nothing happens. Does anyone know how to check the file I've updated through ssh without having to restart the program? I'm looking for answers that I can use on a Linux system (Raspberry Pi 3B).

Thank you in advance!

Code that checks the files:

streampos fileSizeReference = 0;
fatream fileReader("some/random/file.txt", ios::int | ios::out);

fileReader.seekg(0, ios::end);

if( fileReader.tellg() > fileSizeReference ) {
    update();
}
V.Molotov
  • 59
  • 5
  • 1
    Why not use a file event watching system? Most operating systems have hooks for that. You can poll for changes in the file directly. – tadman Jun 26 '20 at 15:19
  • Here's a tool for that: [efsw](https://github.com/SpartanJ/efsw) – rustyx Jun 26 '20 at 15:25
  • The program runs in the same computer as the file? Or do you want to monitor remotely? – Manuel Jun 26 '20 at 15:27
  • I think better solution would be to check file modification time, though you cannot do that through `std::fstream`, you need to use OS specific API or a portable library like boost – Slava Jun 26 '20 at 15:31
  • @Manuel I have the file and the program on the same machine. – V.Molotov Jun 26 '20 at 15:41
  • Can someone here please explain with code how I could do this? – V.Molotov Jun 26 '20 at 15:59
  • @V.Molotov you have links about this in [this](https://stackoverflow.com/questions/61253/how-to-be-notified-of-file-directory-change-in-c-c-ideally-using-posix) response. – Manuel Jun 26 '20 at 16:04
  • 1
    Read the man page for `inotify` ([here's one](https://man7.org/linux/man-pages/man7/inotify.7.html)) and see if it does what you want. Linked man page has usage examples down at the bottom. – user4581301 Jun 26 '20 at 16:04

0 Answers0