Added timeout parameter for waiting after SIGTERM