2019-03-04

    Connected Devices: Run program in RaspberryPi continuously

    In order to run Node script in Pi, I set up a crontab task in Pi last Tuesday after class and left the device running on floor. But it turned out not sending data to server as expected. The challenges I got including:

    1. @reboot command seemed not working properly
    2. Should the script be run as Pi got rebooted and kept running, or to be executed once in an hour by crontab?
    3. Is sudo required in a crontab command?
    4. What's the user role of a crontab command? root or certain user?
    5. I know that we can designate user in /etc/crontab file instead of crontab -e, but is it necessary?

    Because I failed to set the task up properly, I tried to use job control to run the program in the background as Mark suggested. And it worked perfectly.

    Takeaways

    Using job control to run program in the background

    background-job

    Put & at the end of the command to execute and run the script in background constantly. But be careful not to run multiple same programs accidentally. Use ps -aux instead of only ps to show every processes running in background, including those not attached to a terminal . If there's duplicated ones, kill them.