4

このスクリプトの名前は次のdaemon.fishとおりです。

function --on-signal SIGTERM on-signal-sigterm
  echo "SIGTERM captured"
end

set fifo /tmp/asd.fifo

echo "fifo reader [" %self "]"

while test ! -p $fifo
  echo "$fifo is not a fifo" >&2
  sleep 1
end

while true
  if read --local line < $fifo
    echo "line: $line" &
  end
end

スクリプトを起動すると、2 番目のループの実行中にシグナル (fe SIGTERM) をキャプチャできません。

$ fish daemon.fish
> fifo reader [ 15853 ]
> /tmp/asd.fifo is not a fifo
> ...
$ kill -SIGTERM 15853 [in another shell]
> SIGTERM captured
> /tmp/asd.fifo is not a fifo
> ...
$ mkfifo /tmp/asd.fifo
$ kill -SIGTERM 15853 [in another shell]
> [nothing]

bash バージョンは機能するので、問題は魚固有のものだと思います。

trap "echo SIGTERM captured" SIGTERM

fifo=/tmp/asd.fifo

echo "fifo reader [" $$ "]"

while [[ ! -p $fifo ]]; do
  echo "$fifo is not a fifo" >&2
  sleep 1
done

while true; do
  if read line < $fifo; then
    echo "line: $line" &
  fi
done

テスト:

$ rm -f /tmp/asd.txt; and fish daemon.bash
> fifo reader [ 15853 ]
> /tmp/asd.fifo is not a fifo
> ...
$ kill -SIGTERM 15853 [in another shell]
> SIGTERM captured
> /tmp/asd.fifo is not a fifo
> ...
$ mkfifo /tmp/asd.fifo
$ kill -SIGTERM 15853 [in another shell]
> daemon.bash: line 13: /tmp/asd.fifo: Interrupted system call
> SIGTERM captured
4

0 に答える 0