Advertisement
Guest User

Alternative signal handling

a guest
Oct 8th, 2020
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.55 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # a function to repeatedly print the content in "in.txt"
  4. function print_forever() {
  5.     while [ 1 ];
  6.     do
  7.         cat "$1"
  8.         sleep 1
  9.     done
  10. }
  11.  
  12. echo run the hello binary
  13. print_forever in.txt | ./hello &
  14. pid=$!
  15. echo "background process $pid started"
  16.  
  17. trap_ctrlc() {
  18.     echo -e "\n\ntrap_ctrlc\n\n"
  19. }
  20.  
  21. trap trap_ctrlc INT
  22.  
  23. # wait for all background processes to terminate
  24. wait
  25. echo first wait=$?
  26. kill $pid
  27. echo -e "\nkill=$? (0 = success)\n"
  28. wait $pid
  29. echo "wait=$? (the exit status from the background process)"
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement