added a signal handler for SIGTERM and used psignal in signal_handler