📄 ex-19-02_timer.sh
字号:
#!/bin/sh# Chapter 19 - Working with Signals# This script demonstrates how to catch and send signals## Define the variable $PROG in your environment and then# execute this script to see the time in actionAlarmHandler() { echo "Got SIGALARM, cmd took too long." KillSubProcs exit 14}KillSubProcs() { kill ${CHPROCIDS:-$!} if [ $? -eq 0 ] ; then echo "Sub-processes killed." ; fi}SetTimer() { DEF_TOUT=${1:-10}; if [ $DEF_TOUT -ne 0 ] ; then sleep $DEF_TOUT && kill -s 14 $$ & CHPROCIDS="$CHPROCIDS $!" TIMERPROC=$! fi}UnsetTimer() { kill $TIMERPROC }# main()trap AlarmHandler 14SetTimer 15$PROG &CHPROCIDS="$CHPROCIDS $!"wait $!UnsetTimerecho "All Done."exit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -