How to make a bash script that creates 40 simultaneous instances of a program?
You can use a loop and start the processes in the background with &
:
for (( i=0; i<40; i++ )); do
php /home/calculatedata.php &
done
If these processes are the only instances of PHP you have running and you want to kill them all, the easiest way is killall
:
killall php
for instance in {1..40}
do
php myscript &
done
How about running the php process in the background:
#!/bin/bash
for ((i=1;i<=40;i+=1)); do
php /home/calculatedata.php &
done
You can terminate all the instances of these background running PHP process by issuing:
killall php
Make sure you don't have any other php processes running, as they too will be killed. If you have many other PHP processes, then you do something like:
ps -ef | grep /home/calculatedata.php | cut_the_pid | kill -9