Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root@OpenWrt:~/cake-autorate# cat test.sh
- #!/bin/bash
- kill_all()
- {
- trap - INT TERM EXIT
- echo "Killing background with pid=$background_pid"
- kill $background_pid
- wait $background_pid
- }
- kill_background()
- {
- trap - TERM EXIT
- echo "killing pinger with pid=$ping_pid"
- kill $ping_pid
- echo "killed pinger"
- exit
- }
- background()
- {
- trap '' INT
- trap kill_background TERM EXIT
- ping 1.1.1.1&
- ping_pid=$!
- echo "Started ping with pid=$ping_pid"
- sleep inf
- echo "Background exited."
- }
- set -x
- trap kill_all INT TERM EXIT
- background&
- background_pid=$!
- echo "Started test.sh with background_pid=$background_pid"
- sleep inf
- echo "script termination"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement