[clug] killing a looping / hung script?

Luke Mewburn lukem-clug at mewburn.net
Wed Dec 7 01:01:27 UTC 2016


On Tue, Dec 06, 2016 at 05:05:57PM +1100, Paul Wilson wrote:
  | I have a perl script which occasionally goes into a hung or wait state, and
  | wanted to know is there a standard way to automatically kill this process
  | after some timeout (eg 1 min).
  | Note the perl script is doing a Serial port read and for some reason it
  | waits if there is an issue with the Arduino.
  | 
  | ie can I use some sort of wrapper script to check this state and kill it?

[resent with my actual subscribed address]

The old-school way way of doing this in C applications
is using a SIGALRM handler and the alarm() system/library call.

It appears that perl supports an "alarm" keyword:
  http://perldoc.perl.org/functions/alarm.html

That should work in a general script no matter what the long
running event is, including: blocked on I/O; long-running sleep;
CPU loop; etc.


That said, as others mentioned, give that you're using I/O
and it is most likely blocking on the I/O operation, you
might want to consider an I/O polling mechanism (such as select)
or an asynchronous I/O pattern.


cheers,
Luke.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/linux/attachments/20161207/efc61be8/attachment.sig>


More information about the linux mailing list