3

Cent OS で mono を使用して C# プログラムを実行しています。外部入力をこのプログラムに入れることを可能にする fifo があります。

mono プログラムが実行されている screen セッションからの入力もcat受け入れる必要があります。

#! /bin/bash -
echo "Starting server"
mono --gc=sgen Server-CLI.exe < $fifo &
echo $$ > $PIDFILE
cat > $fifo
echo "Server stopped. Cleaning up"
rm -f $fifo
rm -f $PIDFILE

catモノプログラムが終了するたびに終了するにはどうすればよいですか? 現在、mono プログラムが終了しcatてもまだ実行されているため、スクリプトが 2nd に到達することはありませんecho

4

3 に答える 3

2

の PID を保存しますmono。バックグラウンドで実行catし、その PID を保存します。waitの PID に対してmono. これが満たされると、killの PID がcat.

mono &
monoPID=$!
cat &
catPID=$!
wait "$monoPID"
kill "$catPID"
于 2012-06-09T22:12:02.113 に答える
0

cat doesn't die immediately when mono exits because it's waiting on its stdin. As soon as it has some data to send, it will die with a SIGPIPE signal, because the pipe no longer has a process connected to the other end.

Unfortunately I'm not a hardened select guru so I don't know offhand whether it's possible to write a "better" version of cat that checks both stdin and stdout and dies as soon as stdout's other end is closed.

于 2012-06-09T22:48:55.807 に答える
0

$から入手できます!

(cat > $fifo)& 
pid=$!

kill -9 "$pid"
于 2012-06-09T22:10:15.890 に答える