如何使用bash冲洗管道 [英] How to flush a pipe using bash

查看:106
本文介绍了如何使用bash冲洗管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有写入到一个命名管道,从管道中读取的脚本和其他。偶尔,启动脚本的时候我已经注意到,管的内容从脚本的previous运行存在。有没有办法在脚本的开始?

I have a script that writes to a named pipe and another that reads from the pipe. Occasionally, when starting the script I have noticed that the contents of the pipe exist from a previous run of the script. Is there a way to flush out the pipe at the beginning of the script?

推荐答案

我觉得 DD 是您的朋友:

dd if=myfifo iflag=nonblock of=/dev/null

strace的显示

strace shows

open("myfifo", O_RDONLY|O_NONBLOCK)

确实不甚至一个空的FIFO存储块。

and indeed doesn't even block on an empty fifo.

这篇关于如何使用bash冲洗管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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