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

推荐订阅源

V
Visual Studio Blog
S
Schneier on Security
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
美团技术团队
Last Week in AI
Last Week in AI
罗磊的独立博客
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
大猫的无限游戏
大猫的无限游戏
V
V2EX
博客园_首页
博客园 - 司徒正美
IT之家
IT之家
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
雷峰网
雷峰网
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
J
Java Code Geeks
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
P
Privacy International News Feed
C
CERT Recently Published Vulnerability Notes
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
AWS News Blog
AWS News Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threat Research - Cisco Blogs
Jina AI
Jina AI
V
Vulnerabilities – Threatpost
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LINUX DO - 最新话题
N
News and Events Feed by Topic
H
Hacker News: Front Page
腾讯CDC
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
WordPress大学
WordPress大学
爱范儿
爱范儿
T
Tor Project blog
博客园 - 【当耐特】
T
The Exploit Database - CXSecurity.com
K
Kaspersky official blog
Latest news
Latest news
博客园 - 叶小钗
Know Your Adversary
Know Your Adversary
有赞技术团队
有赞技术团队

博客园 - 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