所以我想在后台连续运行这个脚本。我能够在启动时启动它然后运行它,但它会在一段时间后停止运行。怎么了?
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawLine(touchX,0,touchX,canvas.getHeight(),paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
touchX = event.getX();
touchY = event.getY();
/*
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
path.moveTo(touchX,touchY);
break;
case MotionEvent.ACTION_MOVE:
path.lineTo(touchX,touchY);
break;
case MotionEvent.ACTION_UP:
break;
}
*/
invalidate();
return true;
}
答案 0 :(得分:0)
你不应该在initscript中循环运行。 Init将杀死长期运行的initscripts。您可以提取所有逻辑
echo "18" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio18/direction
while true;do
ps cax | grep hairtunes > /dev/null
if [ $? -eq 0 ]; then
echo "0" > /sys/class/gpio/gpio18/value
else
echo "1" > /sys/class/gpio/gpio18/value
fi
sleep 5
done
进入单独的脚本并使用initscipt中的&
运行它。像这样:
#!/bin/sh
### BEGIN INIT INFO
# Provides: myfirst
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: myfirst
# Description: Speaker switch
### END INIT INFO
case "$1" in
start)
/path/to/the/script/above/with/logic.sh &
;;
stop)
# you need to store pid to do this
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
这应该有效。但是,这不是最佳解决方案。最好的方法是正确地将你的过程妖魔化,这是一个不同的主题。