I'm running some simulations for which I have scripts that launch them in a for loop.
Let's say script.sh looks a bit like this
#!/bin/bash
for i in {0..N}
do
# do some stuff
command # this line actually launches the simulation
done
Now, I usually launch several of these scripts at the same time and command is the same for all of them, so if I open top or htop I will have several lines that just say command, their only difference being the PID.
Sometimes, for whatever reason, I need to stop one of these commands, but I don't really know which PID the one I want to stop is. Let's say I start each script.sh from a different directory. Can I do something before starting command to keep track of the PID of each of them, say export their PID to a file, so if in some directory I see something has gone wrong and I need to stop it, I can kill just that one?
Thanks.