2021年4月8日星期四

is it possible to resume the interrupted process after getting SIGTERM singal?

In below program, What I am trying to achieve is when I press Ctrl+C or give SIGTERM then I want to make 'isEnable' false and let the while loop finish executing it's code one last time and exit the program gracefully. I can achieve this only with CancelKeyPress because EventArgs passed on this handler has Cancel property and I just need to set it true. And, CancelKeyPress only handle Ctrl+C. But, I want same thing when I got SIGTERM signal.

Does anyone know is it possible to resuming the process after getting SIGTERM signal just like in CancelKeyPress?

Please let me know if you need more information to understand my question.

class Program      {          static void Main(string[] args)          {              Console.WriteLine("Hello World!");                bool isEnable = true;                Console.CancelKeyPress += (s, e) =>              {                  e.Cancel = true;                  isEnable = false; // making while loop false                  Console.WriteLine("Inside CancelKeyPress");              };                AppDomain.CurrentDomain.ProcessExit += (s, e) =>              {                  isEnable = false;  // making while loop false                  Console.WriteLine("AppDomain ProcessExit!");              };                while (isEnable)              {                  Console.WriteLine("first");                  Thread.Sleep(3000);                  Console.WriteLine("Second");                  Thread.Sleep(3000);                  Console.WriteLine("Third");                  Thread.Sleep(3000);                  Console.WriteLine("Fourth");                  Thread.Sleep(3000);              }                Console.WriteLine("Gracefull Shotdown");            }      }  
https://stackoverflow.com/questions/67014520/is-it-possible-to-resume-the-interrupted-process-after-getting-sigterm-singal April 09, 2021 at 11:04AM

没有评论:

发表评论