Add a service file /lib/systemd/system/picam.service similar to this:
[Service] WorkingDirectory=/home/pi/mydir ExecStart=/usr/bin/python xxx.py Restart=always StandardOutput=syslog StandardError=syslog SyslogIdentifier=picam User=pi Group=pi [Install] WantedBy=multi-user.target
enable then start/stop using:
sudo systemctl enable picam.service
sudo systemctl start picam.service
sudo systemctl stop picam.service
to view the output:
sudo journalctl -u picam.service