| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # This script spawns child processes and then exits early |
| 4 | echo "Parent process started with PID $$" |
| 5 | |
| 6 | # Spawn multiple child processes that will outlive the parent |
| 7 | for i in {1..3}; do |
| 8 | ( |
| 9 | # Child process |
| 10 | child_pid=$BASHPID |
| 11 | echo "Child $i started with PID $child_pid" |
| 12 | |
| 13 | # Spawn a grandchild that runs for a long time |
| 14 | ( |
| 15 | grandchild_pid=$BASHPID |
| 16 | echo "Grandchild of child $i started with PID $grandchild_pid" |
| 17 | # Keep running for 30 seconds with a marker for process assertions |
| 18 | sh -c 'sleep 30; :' parent-exits-early-grandchild |
| 19 | ) & |
| 20 | |
| 21 | # Keep the child running with a marker for process assertions |
| 22 | sh -c 'sleep 30; :' parent-exits-early-child |
| 23 | ) & |
| 24 | done |
| 25 | |
| 26 | # Give children time to start |
| 27 | sleep 0.5 |
| 28 | |
| 29 | # Exit early (simulating a crash or early termination) |
| 30 | echo "Parent exiting early with status 1..." |
| 31 | exit 1 |