在linux启动时运行时我的应用程序速度很低

时间:2018-03-13 08:59:05

标签: linux qt shell linux-kernel startup

我有一个用Qt,C ++创建的嵌入式控制台应用程序。我使用nanopi fire(FriendlyARM)为我的Linux arch设备。我连接它的gpio作为继电器,用于打开和关闭我房间的灯。我还写了移动应用程序来连接设备与插座。当我从putty ./SmartKeyC运行我的程序时,它会运行,我可以用我的移动应用程序按钮切换灯泡,所有这些都没问题。
但是当我启动自动运行程序时,所有功能都会延迟2-3秒完成任务 我使用此link来创建自动运行应用。这是我的剧本:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          <your script name>
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Manage my cool stuff
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/root

. /lib/init/vars.sh
. /lib/lsb/init-functions
. /root/
# If you need to source some other scripts, do it here

case "$1" in
  start)
    log_begin_msg "Starting my super cool service"
# do something
    /root/SmartKeyC
    log_end_msg $?
    exit 0
    ;;
  stop)
    log_begin_msg "Stopping the coolest service ever unfortunately"

    # do something to kill the service or cleanup or nothing

    log_end_msg $?
    exit 0
    ;;
  *)
    echo "Usage: /etc/init.d/<your script> {start|stop}"
    exit 1
    ;;
esac  

在更新rc后我有:

root@NanoPi2-Fire:/etc# find -iname "*SmartKeyScript"
./init.d/SmartKeyScript
./rc0.d/K01SmartKeyScript
./rc1.d/K01SmartKeyScript
./rc2.d/S03SmartKeyScript
./rc3.d/S03SmartKeyScript
./rc4.d/S03SmartKeyScript
./rc5.d/S03SmartKeyScript
./rc6.d/K01SmartKeyScript

问题出在哪里?
为什么当我在putty中运行我的应用程序时,一切正常,但是当我的应用程序从自动运行开始时,每个函数调用都有延迟?

1 个答案:

答案 0 :(得分:0)

我从rcX删除了我的脚本,并将文件放在我的rc.local中,如下所示:

Vi /etc/rc.local
#!/bin/sh -e                                                                                                                                  
#                                                                                                                                             
# rc.local                                                                                                                                    
#                                                                                                                                             
# This script is executed at the end of each multiuser runlevel.                                                                              
# Make sure that the script will "exit 0" on success or any other                                                                             
# value on error.                                                                                                                             
#                                                                                                                                             
# In order to enable or disable this script just change the execution                                                                         
# bits.                                                                                                                                       
#                                                                                                                                             
# By default this script does nothing.                                                                                                        

/usr/local/bin/gen-friendlyelec-release                                                                                                       
. /etc/friendlyelec-release                                                                                                                   
if [ ! -f /etc/firstuse ]; then                                                                                                               
    /bin/echo ${BOARD} > /etc/hostname                                                                                                        
    /bin/sed -i "s/\(127.0.1.1\s*\).*/\1${BOARD}/g" /etc/hosts                                                                                
    /bin/hostname ${BOARD}                                                                                                                    
    /bin/echo "0" > /etc/firstuse                                                                                                             
fi                                                                                                                                            

. /usr/bin/setqt5env                                                                                                                          
/usr/bin/lcd2usb_print "CPU: {{CPU}}" "Mem: {{MEM}}" "IP: {{IP}}" "LoadAvg: {{LOADAVG}}" 2>&1 > /dev/null&                                    
#/opt/QtE-Demo/run.sh&                                                                                                                        
/root/SmartKeyC & > /dev/tty0                                                                                                                 


exit 0