Guest User

Untitled

a guest
May 27th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #!/bin/bash
  2. if [[ -n "$1" ]]; then
  3. sleep 1 &
  4. p=$!
  5. kill $p &> /dev/null
  6. else
  7. sleep 1 &
  8. p=$!
  9. kill $p &> /dev/null
  10. /bin/true # This line is the sole difference.
  11. fi
  12.  
  13. $ ./a.sh
  14. /a.sh: line 16: 18103 Terminated sleep 1
  15. $ ./a.sh foo
  16. $ # no "Terminated" message
  17.  
  18. #!/bin/bash
  19. if [[ -n "$1" ]]; then
  20. sleep 1 &
  21. p=$!
  22. kill $p &> /dev/null
  23. /bin/echo "a line"
  24. else
  25. sleep 1 &
  26. p=$!
  27. kill $p &> /dev/null
  28. fi
  29.  
  30. $ bash ./mystery.sh
  31. $ bash ./mystery.sh foo
  32. a line
  33. ./mystery.sh: line 11: 10361 Terminated sleep 1
  34.  
  35. $ bash ./mystery.sh
  36. $ bash ./mystery.sh foo
  37. a line
  38.  
  39. if [[ -n "$1" ]]; then
  40. sleep 1 &
  41. p=$!
  42. kill $p &> /dev/null
  43.  
  44. $ strace -s 1024 -e kill bash mystery.sh
  45. kill(9830, SIGTERM) = 0
  46. mystery.sh: line 11: 9830 Terminated sleep 1
  47. --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=9830, si_uid=1000, si_status=SIGTERM, si_utime=0, si_stime=0} ---
  48. +++ exited with 0 +++
  49. $ strace -s 1024 -e kill bash mystery.sh foo
  50. kill(9839, SIGTERM) = 0
  51. +++ exited with 0 +++
  52.  
  53. $ strace -s 1024 -e kill,wait4 bash mystery.sh foo
  54. kill(9910, SIGTERM) = 0
  55. +++ exited with 0 +++
  56. $ strace -s 1024 -e kill,wait4 bash mystery.sh
  57. kill(9916, SIGTERM) = 0
  58. --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=9916, si_uid=1000, si_status=SIGTERM, si_utime=0, si_stime=0} ---
  59. wait4(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGTERM}], WNOHANG, NULL) = 9916
  60. wait4(-1, 0x7ffe8e5bb110, WNOHANG, NULL) = -1 ECHILD (No child processes)
  61. wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 9917
  62. mystery.sh: line 11: 9916 Terminated sleep 1
  63. --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9917, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  64. wait4(-1, 0x7ffe8e5bb250, WNOHANG, NULL) = -1 ECHILD (No child processes)
  65. +++ exited with 0 +++
  66.  
  67. #!/bin/bash
  68.  
  69. ## ... copy code from the question above.
  70.  
  71. sleep 0.2
Add Comment
Please, Sign In to add comment