I have multiple processes tailing a file, how can I write an EOF to the file, to stop the tailing processes?for example,tail -F $HOME/somefile.logthat is being run in some terminal somewhere, not sure where.How can I write an EOF to the log file, so that any process which is tailing that file, stops tailing it?In some cases, I am tailing a fifo:mkfifo fiveltail -f fivelI believe that writing an EOF to a named pipe might actually stop/kill any processes tailing the fifo, whereas writing an EOF to a regular file may not stop tailing processes.
Hot to write an EOF to a file, to stop any tailing processes
kill;tail
To me this does not seem like the right way to achieve this.I think you want to target the tail process[es] reading the file instead of the file itself.Consider something like the following instead.ps -ef | grep [t]ail | grep 'somefile.log' | tr -s ' ' | cut -d' ' -f2 | xargs killps -ef will display all processes running on your system.grep [t]ail will will find all processes with tail in the name (excluding this grep).grep 'somefile.log' will find from these the ones with somefile.log in the name.tr -s ' ' will squeeze all multiple spaces down to one.cut -d' ' -f2 will using space as delimiter get only the second column which is the PID.xargs kill will kill that PID.This will kill any tail processes reading the file (bar some strange corner cases e.g. log file called tailsomefile.log).There may be a cleaner way of doing this but this was the first immediately obvious solution to me.I have tested that this is working on Linux.