请问php如何获取exec执行程序的pid?
网友回复
在PHP中,你可以使用exec函数来执行外部程序,并获取该程序的进程ID(PID)。然而,exec函数本身不会直接返回PID。你需要在执行外部程序时,通过适当的命令来获取PID。
以下是一个示例,展示了如何使用PHP的exec函数来获取执行程序的PID:
示例代码<?php // 要执行的命令 $command = 'your-command-here'; // 执行命令并获取输出和返回状态 exec("$command > /dev/null 2>&1 & echo $!", $output); // PID会在$output数组的第一个元素中 $pid = (int)$output[0]; echo "The PID of the executed process is: $pid\n"; ?...
点击查看剩余70%