Welcome to Bo-Blog.
man 中说到:
Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename.
例子:
------ a1.sh ------
#!/bin/sh
./b.sh #如此执行则b.sh 必须有可执行权限
-------------------
------ a2.sh ------
#!/bin/sh
. b.sh #如此写法则b.sh 可以没有可执行权限
-------------------
------ b.sh ------
#!/bin/sh
sleep 100
-------------------
执行:
sh a1.sh #进程中会看到 b.sh
sh a2.sh #进程中不会看到 b.sh
Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename.
例子:
------ a1.sh ------
#!/bin/sh
./b.sh #如此执行则b.sh 必须有可执行权限
-------------------
------ a2.sh ------
#!/bin/sh
. b.sh #如此写法则b.sh 可以没有可执行权限
-------------------
------ b.sh ------
#!/bin/sh
sleep 100
-------------------
执行:
sh a1.sh #进程中会看到 b.sh
sh a2.sh #进程中不会看到 b.sh
PHP不支持多线程编程,于是,当需要同时执行多个任务的时候,就有些力不从心了;对于有些任务可以通过异步的方式来处理,如: 同时执行多个http请求;对于有些计算型的需求,或者是异步实现很麻烦的时候就不好办了。
当我再一次看fork/exec/system/source等类似的命令或系统调用的时候,觉得他们和之间的异同比较有意思,比如:
fork: 创建子进程,当前进程继续运行
exec: 当前进程直接让位于要执行的程序,用不返回
system: 使用当前进程的环境,创建一个子进程,等待子进程执行完成后返回; system=fork+exec+waitpid
于是想到了PHP中的popen,该方法可以和执行一个外部命令,但是不阻塞当前进程,只需要使用循环去收集执行结果就行了。
对于web程序,通过异步的http请求将任务提交给本机的web server或许比popen更加合算一些。
当我再一次看fork/exec/system/source等类似的命令或系统调用的时候,觉得他们和之间的异同比较有意思,比如:
fork: 创建子进程,当前进程继续运行
exec: 当前进程直接让位于要执行的程序,用不返回
system: 使用当前进程的环境,创建一个子进程,等待子进程执行完成后返回; system=fork+exec+waitpid
于是想到了PHP中的popen,该方法可以和执行一个外部命令,但是不阻塞当前进程,只需要使用循环去收集执行结果就行了。
对于web程序,通过异步的http请求将任务提交给本机的web server或许比popen更加合算一些。
情景:
从机器A到机器B发起连接,连接超时时间设置为1s,有一定概率的连接失败的情况,使用下面脚本来测试,不断连接,放过成功的连接,只显示失败的连接,并且显示连接失败的时间,脚本如下:
从机器A到机器B发起连接,连接超时时间设置为1s,有一定概率的连接失败的情况,使用下面脚本来测试,不断连接,放过成功的连接,只显示失败的连接,并且显示连接失败的时间,脚本如下:
- while :; do r=`nc -z -v -w 1 10.79.40.43 11231 2>&1 | grep -v succe`;if [ "x$r" != "x" ]; then d=`date +"%H:%M"`;echo -n "$d "; echo $r; fi ; done
检查网络连通性:
while :; do nc -z -v -w 1 10.79.40.43 11231 | grep -v succe; done
while :; do nc -z -v -w 1 10.79.40.43 11231 | grep -v succe; done




2009/08/16 17:03 | 

