杀死启动时启动的python进程

时间:2013-12-09 09:55:12

标签: python linux process startup

我正在运行基于websocket的小型服务器。出于实际原因,我在启动时通过init.d中的一个小脚启动它:

case "$1" in
  start)
echo "Starting mosaicServer"
# run application you want to start
rm /var/log/process.log
python /var/dir/process.py > /var/log/process.log
;;
 stop)
echo "Stopping process"
# kill application you want to stop
    killall process
    ;;
   *)
    echo "Usage: /etc/init.d/process {start|stop}"
    exit 1
    ;;
esac

exit 0 

问题是我需要终止此流程进行测试,但我似乎无法通过ps -all/etc/init.d/process stop查看流程pid。

如果可以

2 个答案:

答案 0 :(得分:0)

您可以使用

查找流程
ps aux | grep -e "[p]rocess"

[p]是忽略grep进程本身

所以开始部分将包含:

python your_programm.py > $LOGFILE 2>&1 &
ps aux | grep [y]our_programm.py | awk '{print $2}' > $PIDFILE

和停止部分:

if [ -f $PIDFILE ]; then
    PID=`cat $PIDFILE`
    kill -9 $PID
fi

答案 1 :(得分:0)

您可以尝试使用主管运行您的程序。

Supervisor: A Process Control System

相关问题