如何创建一个程序的同时40实例的bash脚本? [英] How to make a bash script that creates 40 simultaneous instances of a program?
问题描述
我是新来的庆典
和的Linux
。
我有一个程序我写,我想创建的多个并发实例。
I am new to bash
and Linux
.
I have a program I have written that I want to create multiple simultaneous instances of.
现在,我通过开辟10个新的终端,然后运行程序10次做到这一点(我运行的命令是 PHP /home/calculatedata.php
Right now, I do this by opening up 10 new terminals, and then running the program 10 times (the command I run is php /home/calculatedata.php
什么是做到这一点最简单的方式使用bash脚本?
另外,我需要知道如何杀死实例,因为他们正在运行一个无限循环。
What is the simplest way to do this using a bash script? Also, I need to know how to kill the instances because they are running an infinite loop.
谢谢!
推荐答案
您可以使用一个循环,并在后台启动过程与&安培;
:
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
如果这些进程是你已经运行PHP的唯一实例,并要杀死他们,最简单的方法是的 killall
:
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
这篇关于如何创建一个程序的同时40实例的bash脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!