Tuesday, February 22, 2022

[SOLVED] My application speed is low when run at linux startup

Issue

I have an embedded console application created with Qt,C++. I use nanopi fire (FriendlyARM) for my device with Linux arch. I connect it's gpio as relay for turning on and off the lamps of my room. Also I wrote mobile app to connect the device with socket. When I run my program from putty ./SmartKeyC it runs and I can switch the lamps with my mobile app buttons and all of them are ok.
But when I put my program on start up for auto run, all of functions do their tasks with 2-3 seconds delay.
I used this link to create auto run app. this is my script:

#! /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  

and after update rc I have:

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

Where is the problem?
Why when I run my app in putty , everything works good , but when my app starts from auto run it has delay for each function calling?


Solution

I remove my script from rcX and put file in my rc.local like below:

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   


Answered By - H.Ghassami
Answer Checked By - Gilberto Lyons (WPSolving Admin)