如何监视FIFO?

编程入门 行业动态 更新时间:2024-10-28 00:29:16
本文介绍了如何监视FIFO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

理想情况下,我想通过设置该流量的只读终端窗口来调试两个进程之间的问题.我可以简单地使用现有的标准linux实用程序吗?

I want to debug an issue between two processes ideally by setting up a read-only terminal window of that traffic. Is this something I can simply use existing, standard linux utilities for?

FIFO位于/run/myfifo,并且在以下过程之一中创建:

The FIFO lives at /run/myfifo and is created in one of the processes with:

/* Create a FIFO if one doesn't already exist */ int createFifo(char *filepath) { if (access(path, F_OK) == -1) { return mkfifo(filepath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); } return 0; }

tail -F /run/myfifo?

推荐答案

有很多方法可以监视它.我希望您有两个过程.一种过程是写给fifo,另一种过程是读.

There are various options how to monitor that. I expect you have two processes. One process is writing to the fifo and the other is reading.

如果您需要分别调试读写器,则可以使用像cat这样的简单程序.

If you need to debug reader and writer separately than you can use a simple program like cat.

writer-process # and in another terminal cat /run/myfifo

reader-process & # and in another terminal cat > /run/myfifo

当同时需要调试编写器和读取器时,可以使用Daniel Schepler建议的strace. strace可以与您的程序一起运行,在这种情况下,日志记录输出将重定向到另一个终端/dev/pts/4.

When you need debug writer and reader together you can use strace that Daniel Schepler recommended. The strace can be run together with your program and the logging output is redirected to another terminal /dev/pts/4 in this case.

strace -e read -s 999 reader-process 2> /dev/pts/4

该命令记录来自所有文件描述符的所有读取调用.如果要仅过滤从管道读取的内容,则必须标识fifo文件描述符并grep输出.

The command logs all read calls from all file descriptors. If you want to filter only read from pipe you must identify the fifo file descriptor and grep the output.

如果不是strace,则可以强制读取器和写入器使用不同的fifo名称,然后将这两个fifo连接到记录传输数据的程序中.这种连接器的最简单变体可以是类似

If the strace not an option you can parhaps force the reader and writer to use a different fifo names and then connect these two fifos in a program that logs the transferred data. The simplest variant of such a connector can be a script like

cat < /run/mywritefifo | tee /dev/tty > /run/myreadfifo

更多推荐

如何监视FIFO?

本文发布于:2023-11-30 05:10:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648835.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:FIFO

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!