Мне нравится записывать выходные данные программ по запросу. Например. выход записывается на терминал, но другой процесс может подключаться к текущему выходу в любое время.
Классический способ:
myprogram 2>&1 | tee /tmp/mylog
и по запросу
tail /tmp/mylog
Однако это создаст постоянно растущий файл журнала, даже если он не используется до тех пор, пока на диске не закончится свободное пространство. Итак, моя попытка:
mkfifo /tmp/mylog
myprogram 2>&1 | tee /tmp/mylog
и по запросу
cat /tmp/mylog
Теперь я могу читать /tmp/mylog в любое время. Однако любой выход блокирует программу, пока не будет прочитан /tmp/mylog. Мне нравится, что fifo очищает любые входящие данные, которые не читаются. Как это сделать?