Re: [clug] killing a looping / hung script?
Luke Mewburn <[email protected]> Wed, 7 Dec 2016 12:01:27 +1100
| Newsgroups | gmane.org.user-groups.clug |
|---|---|
| Message-ID | <[email protected]> |
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. -- linux mailing list [email protected] https://lists.samba.org/mailman/listinfo/linux
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) iEYEARECAAYFAlhHX2cACgkQpBhtmn8zJHI8YACgjjiNMXICnALDWe2ZR16H7kep dlgAn0tzu8N/ui+60aa/3q2jCoyu5DZq =PVe6 -----END PGP SIGNATURE-----