How to set timeout for a cmd command?

cmd, perl

Solution

Inside of Perl, you can set an alarm to go off after a few seconds. You can then use a signal handler to catch the event. Only one alarm may be active at any time

{ # enter new scope
    # set signal handler
    local $SIG{ALRM} = sub {
       # do cleanup, like closing sockets or whatever
       print STDERR "exited with ALARM\n";
       exit;
    };
    alarm 30; # try half a minute
    ...; # do expensive stuff
}

Problem

i just have the following command in cmd ``` perl csv2rrd3.pl ``` but it always run for a long time. Is there any way to set a timeout for it? or i should do it in the perl script?? And how? Thanks

Original source