Bash: Creating and Managing Child Processes
6 points by benjacksondev 17 hours ago | 2 comments
  • PopGreene 12 hours ago |
    There's something I don't understand. In the trap line for the parent process, the variable "$child_pid" appears. How did that get set?
    • benjacksondev 7 hours ago |
      Hey PopGreene, initially, `$child_pid` was set, but I refactored to use `$!` throughout instead. It must have been an oversight when I refactored `$child_pid` out, as the script still passes with the `$child_pid` not set. This is because running `wait` without an argument exits successfully. With `$child_pid` no longer set, it should be replaced with `$!`; otherwise, the script does not wait until the child process is terminated.

      To clarify, the `wait` is there to avoid zombie processes, which is the script's intention; it should not be `$child_pid` but instead `$!`.

      I've amended the post; thank you.