title: How can I terminate a system command with alarm in Perl?
body: <p>I am running the below code snippet on Windows. The server starts listening continuously after reading from  client. I want to terminate this command after a time period.</p>
  
  <p>If I use <a href="http://perldoc.perl.org/functions/alarm.html" rel="noreferrer">alarm()</a> function call within <code>main.pl</code>, then it terminates the whole Perl program (here <code>main.pl</code>), so I called this <a href="http://perldoc.perl.org/functions/system.html" rel="noreferrer">system</a> command by placing it in a separate Perl file 
  and calling this Perl file (<code>alarm.pl</code>) in the original Perl File using the <a href="http://perldoc.perl.org/functions/system.html" rel="noreferrer">system</a> command.</p>
  
  <p>But in this way I was unable to take the output of this <code>system()</code> call neither in the original Perl File nor in  called one Perl File.</p>
  
  <p>Could anybody please let me know  the way to terminate a <code>system()</code> call or take the output in that way I used above?</p>
  
  <h3>main.pl</h3>
  
  <pre><code>my @output = system("alarm.pl");
  print"one iperf completed\n";
  
  open FILE, "&gt;display.txt" or die $!; 
  print FILE @output_1; 
  close FILE;
  </code></pre>
  
  <h3>alarm.pl</h3>
  
  <pre><code>alarm 30;
  my @output_1 = readpipe("adb shell cd /data/app; ./iperf -u -s -p 5001");
  
  open FILE, "&gt;display.txt" or die $!; 
  print FILE @output_1; 
  close FILE;
  </code></pre>
  
  <p>In both ways <code>display.txt</code> is always empty.</p>