I'm doing a project where raspberry pi runs headless. I have written two python programs, one for swiching off the raspberry pi via gpio push button and the other is a opencv-python program. I need to run both the programs at startup and both are endless scripts . The first program shutdown rpi safely when the button is pressed and other does image processing. How to run both automatically when rpi is started ?
Look into using Supervisor to manage your scripts. It is available as a package for Raspbian.
Supervisor can restart the scripts if they crash and capture any the output and log it. It can also run the script as a non-privileged user if you want.