How to solve hang issue in script?

i have one function block in the beginning of my script and there are some commands inside that function which will perform some operations.

And i am invoking that function from my main script by passing some values. Sometimes it is hanging in the middle for some value.

For example:
For 1st value (one) it is giving the output.
For 2nd value (two) it is hanging to retrieve the result due to server hang/connectivity issue. It hangs and not coming out and not processing the next value (three).

In this situation, i want the script to echo some value (ex: echo HANGING) and proceed with the next value (three) if the current process hangs (i.e, two) after trying for some specified minutes (ex: 2 mins).

i.e, if the func() is not given the o/p with in 2 mins it should echo HANGING. Please help me on this.

fun()
{
example: tnsping $i
....
....
....
}

for i in one two three
do
check=`fun@i`
echo $check >> test
done

hsouldn't it be like this?

fun()
{
example: tnsping "${1}"
....
....
....
}

for i in one two three
do
  check=`fun "${i}"`
  echo $check >> test
done

Yes.. But this also works... You can ignore whatever i have given inside fun().. Becoz in my original script it will connect to db and fetch some details. It is hanging for some dbs due to sever hang/connectivity slowness.

fun()
{
echo $i-- any commands
}

for i in one two three
do
check=`fun @i`
echo $check >> test
done

Perhaps your OS has a timeout command?

man timeout