Strange terminal behaviour after killing ssh

Hi,

We have a problem where occasionally an ssh will hang for no apparent reason preventing the rest of the script continuing. To deal with this I am trying to write a wrapper script to kill a hung ssh command after a specified period.

The scripts use a sleep command running in the background to determine the timeout period. However after I kill the ssh command the terminal goes (for want of a better word) weird. The sysmptoms are:
Unable to type anything
Pressing enter brings up a new line prompt but on the same line as the previous one (sorry I'm not sure on the real terminology - the text at the start showing the current directory)
Ctrl C works the way I would expect enter to work.

I have two versions of the script, one of which always tries to kill the ssh command when the sleep command exits and the other of which only tries to do it, if it has not already died. Both exhibit the same syptoms following the ssh kill so I have currently only posted one here.

#!/usr/bin/ksh

# Set up a sleep thread that will run in the background and simply sleep for the requisite number of seconds.
sleep $1 &
sleep_pid=$!
echo $sleep_pid
# Set up the SSH thread to run the command. Also runs in the background
ssh -t -t $2 $3 $4 $5 $6 $7 $8 $9 &
ssh_pid=$!
while :
do
  ssh_cnt=$(ps -eaf | grep $ssh_pid | wc -l)
  sleep_cnt=$(ps -eaf | grep $sleep_pid | wc -l)
  if [ 1 -eq $ssh_cnt ]
  then
    if [ 1 -lt $sleep_cnt ]
    then
      kill -11 $sleep_pid
      break
    fi
  else
    if [ 1 -eq $sleep_cnt ]
    then
      kill -11 $ssh_pid
      break
    fi
  fi
done

To me it seems like the kill command hasn't killed everything that it needs to, but I really have no idea and wondered if you could help. I am testing this performing an ssh that requires a password so that it hangs.

Apparently it doesn't clean up after itself when killed in that fashion. If you killed it with a less severe signal than SEGV it might. Give it TERM, then QUIT, then KILL if those don't work.

You can reset the terminal characteristics back to normal with reset.

ooh, you are wonderful. I changed it to kill -15 $ssh_pid and it seems to all be working fine. Thank-you so much.