0

I have some programs that that need to run in order with a common task between each program that modifies the data and sends it to another location for processing. each modify_data script spawns several child threads after it copies the main data. I want to keep track of all the child threads and if something fails in a main program I might need to kill off the spawned child threads of 1 or more running modify_data scripts depending on how far back I need to restart processing.

I know i can use pkill -STOP -P $desired_PID if I know what the parent ID is but I need a good way to track the pid's of the modify_data scripts and remove them once they finish running so I dont accidentally kill off something else. My naive solution is to record $$ when spawning each script to some environmental variable and remove it from that variable inside the script once it finishes running but I see several issues with that and I suspect a better solution has already been created.

ex of driver program:

progr1
prog2
modify_data.sh && active_pid="$active_pid $$"
prog3
modify_prog.sh && active_pid="$active_pid $$"
prog4
prog5
prog6
modify_prog.sh && active_pid="$active $$"
...
2
  • 1. Do you have control over modify_data script, or is it something you cannot change/edit? 2. Are the children of the modify_data remain with their parent pid, or is there a chance they're disconnecting from the parent, and if so - do you need to kill them as well? 3. Are there also grandchildren, or only direct children to the monitored scripts?
    – aviro
    Feb 24, 2022 at 8:39
  • @aviro I can push for tweaks but dont have direct control. 2) the child processes are spawned in the background but not disowned, the goal is to have modify_data.sh end after spawning the child threads. 3) no grandchildren
    – guest
    Feb 24, 2022 at 13:31

0

You must log in to answer this question.

Browse other questions tagged .