Tag: 阻塞

如何阻止在Ruby中读取命名管道?

我正在尝试设置一个Ruby脚本,该脚本从循环中的命名管道读取,阻塞直到管道中的输入可用。 我有一个进程,定期将调试事件放入命名管道: # Open the logging pipe log = File.open(“log_pipe”, “w+”) #’log_pipe’ created in shell using mkfifo … # An interesting event happens log.puts “Interesting event #4291 occurred” log.flush … 然后,我想要一个单独的进程,它将从此管道读取并在事件发生时将事件打印到控制台。 我试过使用这样的代码: input = File.open(“log_pipe”, “r+”) while true puts input.gets #I expect this to block and wait for input end # Kill loop with ctrl+c […]