如何监视FIFO? [英] How can I monitor a FIFO?

查看:70
本文介绍了如何监视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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆