Can I tell perl to emit an alarm / signal when the runtime exceeds a certain period without exiting?

I am trying to set an alarm type call that lets me know if my program has been running for more than 10 minutes. I want the program to continue to work after it sends an alarm or a signal. I thought I could make the following code, but the program stops when the execution time reaches ten minutes.

eval{
     local $SIG{ALRM} = sub { die "alarm\n"; };
     alarm (600);
     --code---
     alarm 0;
};
if($@){
     print "\Its been ten minutes\n";
}

I want the application to notify me, but to continue working.

+4
source share
1 answer

Do not die in alarm and everything will be alright

local $SIG{ALRM} = sub { print "Its been ten minutes\n"; };
+6
source

Source: https://habr.com/ru/post/1544050/


All Articles