使用flock的方式解决:
flock -xn test.lock -c 'sh task.sh'
flock -xn test.lock -c 'php -d memory_limimt=-1 /home/test/test.php'