closes file pointers after usage
generates pid file for process control