相关疑难解决方法(0)

使用带有bash的命名管道 - 数据丢失问题

做了一些在线搜索,找到了使用命名管道的简单"教程".但是,当我对后台工作做任何事情时,我似乎丢失了大量数据.

[[编辑:发现一个更简单的解决方案,请参阅回复帖子.所以我提出的问题现在是学术性的 - 如果有人想要一个工作服务器]]

使用Ubuntu 10.04和Linux 2.6.32-25-generic#45-Ubuntu SMP Sat Oct 16 19:52:42 UTC 2010 x86_64 GNU/Linux

GNU bash,版本4.1.5(1)-release(x86_64-pc-linux-gnu).

我的bash功能是:

function jqs
{
  pipe=/tmp/__job_control_manager__
  trap "rm -f $pipe; exit"  EXIT SIGKILL

  if [[ ! -p "$pipe" ]]; then
      mkfifo "$pipe"
  fi

  while true
  do
    if read txt <"$pipe"
    then
      echo "$(date +'%Y'): new text is [[$txt]]"

      if [[ "$txt" == 'quit' ]]
      then
    break
      fi
    fi
  done
}
Run Code Online (Sandbox Code Playgroud)

我在后台运行:

> jqs&
[1] 5336
Run Code Online (Sandbox Code Playgroud)

现在我喂它:

for i in 1 2 3 4 …
Run Code Online (Sandbox Code Playgroud)

linux bash named-pipes data-loss

14
推荐指数
2
解决办法
1万
查看次数

标签 统计

bash ×1

data-loss ×1

linux ×1

named-pipes ×1