Rewrite of signal handler, pid file

Rewrite signal handler.
Adding pid file support.