killing a co-process in ksh

From: Archie (nrautela_at_gmail.com)
Date: 06/29/05


Date: 29 Jun 2005 04:38:58 -0700

Hi,

I have the following script. All I am trying to do is create a
co-process in ksh and then delete it from the main. However I am
getting an error that says
Usage: kill [ -s signame | -signum | -signame ] {pid|job}...
       kill -l [exit_status]
Please advise.

#!/usr/bin/ksh

function trap_exit
{
    breakOut='Y'
    print -p $breakOut
}
function backgroundProc
{
    sleptSecs=0
    read $breakOut

    while [[ $breakOut = 'N' ]]
    do
        sleep 1;
        sleptSecs=`expr $sleptSecs + 1`
        echo "Slept for $sleptSecs\n"
        read $breakOut
    done
}

trap 'trap_exit; exit 2' 1 2 3 15

numSecondsToWait=10

breakOut='N'

backgroundProc |&

backgroundProcPid=$1

echo "proc id is $backgroundProcPid"

sleep $numSecondsToWait

breakOut='Y'

print -p $breakOut

kill backgroundProcPid

exit 0