我想开始n脚本的线程,每个脚本都有自己的进程ID。如何产生一个脚本的n个线程,每个脚本都有自己的进程ID?
我目前通过cronjob
做到这一点,像这样:
* * * * * php /path/to/script.php >> /log/script.log 2>&1
* * * * * php /path/to/script.php >> /log/script.log 2>&1
* * * * * php /path/to/script.php >> /log/script.log 2>&1
这三个线程都登录到同一script.log
,其中对输出其pid
。
如何在不从脚本复制/粘贴的情况下执行相同操作?
以下会产生不同的pid
(可从php
的getmypid()
访问)吗?或者他们都会共享相同的script-launcher.sh
pid?
#!/bin/bash
# Let's call this `script-launcher.sh`
# Launch 3 threads at once with `script-launcher.sh 3`
N=${1-0}
for i in {1..$N}
do
php /path/to/script.php >> /log/script.log 2>&1
done
所有正在运行的进程都有一个唯一的PID。 – pvg
我是否理解你说,使用上面的例子,'script-launcher.sh 100'会产生100个'script.php'进程,每个进程都有自己的'pid'? – Ryan
我认为这可以帮助你http://stackoverflow.com/questions/19543139/bash-script-processing-commands-in-parallel你想为你的脚本开始更多的并行过程吗?当你开始一个过程时,他会自动采取一个pid。 – Laurentiu