Question:
Some program constantly appends a certain number of lines to the Nth number of files. I need to check in a loop whether the file has changed, and if something has been added to it, then read this information. All files have the usual .txt extension. Is there already a ready-made solution in the qt framework? so to speak "out of the box".
Answer:
There is a tail
bike from GNU core utilities
.
# dpkg -S `which tail`
coreutils: /usr/bin/tail
You can run tail -F /var/log/*.log
, the -F
flag tells the utility to watch for changes.
Thus your problem is solved.
Raw tail on c
: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c
Nightmarish of course, but only 2400 lines.
2234 int main (int argc, char **argv) {
headers (headers) are filled there, then on the line
2328 for (i = 0; i < n_files; i++) ok &= tail_file (&F[i], n_units);
a matryoshka from tails is launched on files that are already in the headers.
1885 static bool tail_file (struct File_spec *f, uintmax_t n_units) {
inside, just tail() is called
1871 static bool tail (const char *filename, int fd, uintmax_t n_units, uintmax_t *read_pos)
tail_lines()
is called there
1809 static bool tail_lines (const char *pretty_filename, int fd, uintmax_t n_lines, uintmax_t *read_pos)
And further there simply lseek-ami pieces are extended… In general, can help.
As a last resort, you can run tail -F {Ваш,Список,Файлов}
as a subprocess, and pipe from it…