1#!/usr/bin/env bash
2
3# This script spawns child processes to test process group cleanup
4echo "Parent process started with PID $$"
5
6# Spawn multiple child processes
7for 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 60 seconds
18 for _ in {1..60}; do
19 sleep 1
20 done
21 ) &
22
23 # Keep the child running
24 for _ in {1..60}; do
25 sleep 1
26 done
27 ) &
28done
29
30# Keep the parent running
31echo "Parent process waiting..."
32wait