ex-19-02_timer.sh

来自「Berkely的学生写的」· Shell 代码 · 共 43 行

SH
43
字号
#!/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 + =
减小字号Ctrl + -
显示快捷键?