I have a script which runs a background process at the beginning, then towards the end needs to stop that background process and its children, THEN do some other tasks etc t
You need to capture the value of $! (the child PID) right after
$!
/some_process_with_child_processes & pid=$! ./do_stuff kill $pid ./do_other_stuff