pgrep命令没有返回PID

时间:2015-04-26 14:42:28

标签: linux

我正在尝试查找进程的PID(motion_sensor.py),但pgrep什么都不返回。为什么它不返回进程ID?

pgrep -u www-data motion_sensor.py

ps -ef | grep“motion_sensor”返回

root      7149     1 93 Apr25 ?        15:59:08 python motion_sensor.py
www-data 31872 23531  0 14:09 ?        00:00:00 sh -c sudo python /home/pi/Desktop/PiControl/motion_sensor.py
root     31873 31872  0 14:09 ?        00:00:00 sudo python /home/pi/Desktop/PiControl/motion_sensor.py
root     31874 31873 47 14:09 ?        00:14:30 python /home/pi/Desktop/PiControl/motion_sensor.py
pi       32645 32202  0 14:39 pts/0    00:00:00 grep --color=auto motion_sensor.py

2 个答案:

答案 0 :(得分:1)

通常pgrep将搜索模式应用于进程名称。在这种情况下,流程名称为python而不是motion_sensor.py。如果您想要获取完整路径而不仅仅是流程名称,则需要传递-f

pgrep -u www-data -f motion_sensor.py

检查man pgrep

答案 1 :(得分:0)

要求是找出一个过程的PID, 所以你可以尝试:

ps aux | grep www-data motion_sensor.py