tamalsaha / learn-bash

0 stars 0 forks source link

SIGTERM to background process in bash #31

Open tamalsaha opened 3 years ago

tamalsaha commented 3 years ago
#!/bin/bash 

_term() { 
  echo "Caught SIGTERM signal!" 
  kill -TERM "$child" 2>/dev/null
}

trap _term SIGTERM

echo "Doing some initial work...";
/bin/start/main/server --nodaemon &

child=$! 
wait "$child"