Just run your normal executable with &
./yourexe &
or, if you don't process SIGHUP
nohup ./yourexe &
thats it. Nothing special needs to be done (So you don't need 'inidaemon' function)
To kill, even if you trap signals like in your app above, just use kill:
kill -9 <pid>
You can't ignore or protect against kill -9
Bookmarks