I have a script used to test the sftp connection which runs too long, so I want to time it out after a given number of seconds.After a google search and perl doc reading, I find the ALARM function can work well.
#!/usr/bin/perl
eval {
local %SIG;//in some ENV %SIG should be global variable
$SIG{ALRM}= sub{ die "timeout reached, after 20 seconds!\n"; };
alarm 20;
print "sleeping for 60 seconds\n";
sleep 60; # This is where to put your code, between the alarms
alarm 0;
};
alarm 0;
if($@) { print "Error: $@\n"; }
exit(0);
reference:http://perl.coding-school.com/perl-timeout/
分享到:
相关推荐
Handling Server Timeout Cases and Working with $SIG{ALRM} Section 6.11. Generating Correct HTTP Headers <br> Section 6.12. Method Handlers: The Browse and See, Browse and View Example ...
out http://www.perl.com for the latest book critiques. Is This Book for You? Some of you already know why you picked up this book. But others may just have a nagging feeling that it's something ...
ls -t (time)按修改时间排序,显示目录和文件。 ls -lt 是“-l”和“-t”的组合,按时间顺序显示列表。 ls -F 显示文件类型,目录“/ ”结尾;可执行文件“*”结尾;文本文件(none),没有结尾。 ls -R 递归显示...
Using Perl-Style regexes to identify functions in your syntax-highlighted files and populate the function list Autocorrect keywords in UltraEdit/UEStudio How to enable and disable autocorrect keywords...
5. **Snooze/Timeout Features:** These features help handle unpredictable pop-ups or wait times for Java components. Additional functionality tested includes: 1. **Multiple Java Client Interaction:**...
rslt = WS.Popup(Message, timeout, title, buttons); if (rslt == 2) { WScript.Quit; } } showit(); ``` 2. **网络信息显示**:此示例演示了如何使用WSH获取并显示当前用户的网络信息,包括用户名、域和...
By the time the event gets here, the input form data (or HTML form data) has already been translated out of the request stream and into an ActionForm class. Struts, an MVC 2 implementation Struts...
Changes in 2.4.6 (February 22, 2011): Brief summary : - Support more host OS to run on: - Include win64 native binary in the ... [2914433] makesym.perl misses symbols by John R. Jackson [2908481] USB ...
**2.3 充分利用终端、xterm 和 X Windows (Chapter 5: Getting the Most out of Terminals, xterm, and X Windows)** - **终端模拟器**: xterm 的高级功能介绍。 - **X Window系统**: 基础概念和管理技巧。 - **多...
<#assign mail="jsmith@other.com" in my> ${my.mail} l 输出结果: jsmith@acme.com jsmith@other.com l 数据模型中的变量任何地方都可见,也包括不同的名字空间,下面是修改的库: <p>Copyright ...
The VAPI-XP testing tool enables you to create new testing scripts using Microsoft VBScript, Microsoft JavaScript (JScript version), PerlScript, and PythonScript, and integrate these scripts into your...
22. **定时运行命令**:`timeout` 命令可以限制命令执行时间,如`timeout 10s ./script.sh`。 23. **合并两个已排序文件的行**:`comm` 命令比较两个已排序文件,`comm file1 file2` 显示不同和共有的行。 24. **...