惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
有赞技术团队
有赞技术团队
博客园 - Franky
J
Java Code Geeks
美团技术团队
WordPress大学
WordPress大学
V
Visual Studio Blog
量子位
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
爱范儿
爱范儿
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
The Cloudflare Blog
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
博客园_首页
U
Unit 42
O
OpenAI News
T
The Blog of Author Tim Ferriss
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
S
SegmentFault 最新的问题
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
A
About on SuperTechFans
AWS News Blog
AWS News Blog
Recorded Future
Recorded Future
A
Arctic Wolf
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tenable Blog
大猫的无限游戏
大猫的无限游戏
I
Intezer
K
Kaspersky official blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Register - Security
The Register - Security
G
Google Developers Blog
雷峰网
雷峰网
V
Vulnerabilities – Threatpost

博客园 - Jeff

4个月 C++ 有限状态机 POJ1019 POJ1035 POJ1007 POJ1005 ONLINE_JUDGE 怪异的grep结果 URL2FILE C primer笔记 Vxworks增加system call C语言常用宏定义技巧 分苹果 Socket 为什么选择SMP而不是AMP RTP memory in Vxworks Windriver的项目类型 RTP affinity Symmetric multiprocessing (SMP)
Linux shell定时器
Jeff · 2011-12-26 · via 博客园 - Jeff

2011-12-26 16:02  Jeff  阅读(11757)  评论()    收藏  举报

网上找了个例子,简单实用如下. 可以有一个后台进程,在timer超时采取一些操作.

 
#!/bin/ksh
#Delaytime=0
AlarmHandler()
{
echo "Get SIGALAM"
KillSubProcs
exit 14
}
KillSubProcs()
{
#kill cbm
echo "it's time out,kill cbm here"
if [ $? -eq 0 ];then
echo "Sub-processes killed."
fi
}

SetTimer()
{
Delaytime=$1
echo $Delaytime
if [ $Delaytime  -ne 0 ];then
sleep $Delaytime  && kill -s 14 $$ &
#CHPROCIDS="$CHPROCIDS $!"
TIMERPROC=$!
fi
}
UnsetTimer()
{
echo "Start to unset timer"
kill $TIMERPROC
}

trap AlarmHandler 14
SetTimer 30
#CHPROCIDS="$CHPROCIDS $!"
#wait $!
sleep 40
UnsetTimer
echo "ALL Done."
exit 0