简体   繁体   English

如何使用Java在Linux中读取命名管道(FIFO)

[英]How to read named pipe(FIFO) that in linux using java

I have a problem, where I have to read streaming data from a pipe, to which an application written in C writes data. 我有一个问题,我必须从管道读取流数据,用C编写的应用程序会将数据写入该管道。 another application written in java has to read from this linux pipe. 用Java编写的另一个应用程序必须从此linux管道读取。 This java program is a multi threaded program, to read data from that pipe when other program write data into it. 此Java程序是一个多线程程序,用于在其他程序向其中写入数据时从该管道读取数据。 And it should be continuously reading from pipe, as data being added to pipe queue. 并且应该不断从管道读取数据,因为数据已添加到管道队列中。 Any suggestions would be helpful. 任何的意见都将会有帮助。

Problem trying to solve is: 尝试解决的问题是:

Currently one application(in C) creates files real-time continuously to a directory , and another application(in java) read and process those files. 当前,一个应用程序(用C语言编写)连续实时地将文件创建到目录中,而另一个应用程序(用Java语言编写)读取并处理这些文件。 in this approach there is some time delay because of writing and reading from files from different directories, Hoping using Linux pipe could help to reduce that time delay. 在这种方法中,由于要从不同目录中写入文件并从中读取文件,因此会存在一些时间延迟,使用Linux管道进行跳跃可以帮助减少该时间延迟。 Is there any other better approach to handle continuous large volumes of data? 还有其他更好的方法来处理连续的大量数据吗?

I googled for some sample examples for this to read fifo using multi-thread java program. 我用谷歌搜索了一些示例示例,以使用多线程Java程序读取fifo。 I could not find any suitable examples, Please share if you come across any of such. 我找不到任何合适的示例,如果您遇到任何此类示例,请分享。

If you create a FIFO file, you will not actually write to disk, it will just be a file in the filesystem to make it easier to access. 如果创建FIFO文件,则实际上不会写入磁盘,它只是文件系统中的一个文件,以使其易于访问。 You can read up on it on the man pages of fifo(7) ( man 7 fifo ) for information about FIFOs and mkfifo(1) ( man 1 mkfifo ) for a command to make them in C. 您可以在fifo(7)( man 7 fifo )的手册页上阅读有关FIFO的信息,并在mkfifo(1)( man 1 mkfifo )上获取在C中制作它们的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM