- 论坛徽章:
- 0
|
#!/bin/ksh
#############################################################
#
# COPYLEFT OF WRL, 2009
#
#############################################################
# SCRIPT: coproc22.sh
# AUTHOR: Randy/wrl
# DATE: 20090507
# REV: 1.0
#
# PLATFORM: RHEL5
#
# PURPOSE: demo program of co-process
#
# REV LIST:
# DATE:
# BY:
# MODIFICATION:
#
# set -n # Uncomment to check your syntax, without execution.
# # NOTE: Do not forget to put the comment back in or
# # the shell script will not execute!
# set -x # Uncomment to debug this shell script (Korn shell only)
#
##########################################################
########### DEFINE FILES AND VARIABLES HERE ##############
##########################################################
total_seconds=10
break_out="N"
##########################################################
############### DEFINE FUNCTIONS HERE ####################
##########################################################
function trap_exit
{
break_out="S"
print -p $break_out #send instruction S to proc_watch
exit 1
}
function proc_watch
{
echo "" >/dev/pts/2
while true
do
read break_out
if [ "x$break_out" = "xT" ]; then
echo "function exits after time out." >/dev/pts/2
return 0
elif [ "x$break_out" = "xS" ]; then
echo "function exits after received terminal signal!" >/dev/pts/2
return 1
else
echo "function proc_watch is running at `date` ..." >/dev/pts/2
fi
done
}
##########################################################
################ BEGINNING OF MAIN #######################
##########################################################
trap 'trap_exit' 1 2 3 15 #capture terminal signal
proc_watch |& #send the function to background
while [ $total_seconds -gt 0 ]
do
print -p $break_out #send instruction "N" to proc_watch
total_seconds=`expr $total_seconds - 1`
sleep 1
done
break_out="T"
print -p $break_out #send instruction "T" to proc_watch
exit 0
# End of script |
评分
-
查看全部评分
|