If you are looking for a clean approach please consider using standard api- int daemon(int nochdir, int noclose);
. Man page pretty simple and self explanatory. man page. A well tested api far outweigh our own implementation interms of portability and stability.