From 56a7459d7cad0fcd0add961d45cc46d1032bfa51 Mon Sep 17 00:00:00 2001 From: cy83rt00n Date: Fri, 13 Aug 2021 20:23:45 +0300 Subject: [PATCH] Add signal handler function --- run | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/run b/run index 153b562..8832674 100755 --- a/run +++ b/run @@ -15,13 +15,20 @@ rm -f $IN_PIPE; mkfifo $IN_PIPE; # run the server -cat $WS_PIPE | ./pipe_to_websocket.sh $IN_PIPE | nc -l -p $SERVER_PORT > $WS_PIPE & +cat $WS_PIPE | $(realpath "$(dirname "${BASH_SOURCE[0]}")")/pipe_to_websocket.sh $IN_PIPE | nc -l -p $SERVER_PORT > $WS_PIPE & serverpid=$! +sig_handler() { + printf "\nProcess interrupted. Exiting PID %d\n" $serverpid + kill $serverpid + exit 0 +} + +trap sig_handler SIGHUP SIGKILL SIGINT SIGSTOP + # input loop while read line do echo "$line" >> $IN_PIPE; done -kill $serverpid