© 2023 PodTECH IO
All rights reserved.

Get in Touch

Perl

Perl – Fork and Kill a System Process on Timeout

Perl – Fork and Kill a System Process on Timeout [perl] $pid = open(PIPE, “$command |”) or die $!; eval { local $SIG{ALRM} = sub { die “TIMEOUT” }; alarm($timeout); while (<PIPE>) { $data = $_; }; close(PIPE); alarm(0); }; if ($@) { die $@ unless $@ =~ /TIMEOUT/; kill 15, $pid; close(PIPE); $? ||= […]