You can save the PID when starting processes, so you can use them later:
nohup ./start-gossip & START_GOSSIP_PID=$! nohup ./start & START_PID=$! nohup ./start-admin & START_ADMIN_PID=$! ... kill -9 $START_GOSSIP_PID kill -9 $START_PID kill -9 $START_ADMIN_PID
This has the advantage (more than pkill ) of not destroying any other processes that coincidentally have similar names. If you do not want to perform the kill operation from the script itself, but just want the PIDs to be convenient, write them to a file (from the script):
echo $START_GOSSIP_PID > /some/path/start_gossip.pid
Or just do it when you start the process, and not save the PID for the variable:
nohup ./start-gossip & echo $! > /some/path/start_gossip.pid
source share