how trap the signals in shell scripting

Hi all,
I have the c program that c program has to be in sleep mode.
I want write a script the it should trap the signal from the c program.
The signals are sighup,sigkill,sigterm,sigchld and then it has to go to sleep.
If signal is sigchld it has to do to some function.
My question is how to write the script to trap the signal.
I know the trap commnad but i dont know how to trap the signals.
Please help me in this issue.
Please let me if you didnt understand my question.
Thanks in advance.
Vijay,

You cannot trap all signals - some are processed regardless of the the trap

kill -l

shows the names and numbers of all of the signals you system uses. There are differences between unixes in what this display shows.

Suppose you want to trap control/c - SIGINT, signal =2 on my system.
You can use either the number 2 or the name - drop the "SIG" part and you can use INT

#!/bin/ksh
trap 'echo "control/c ignored" ' INT

[/code]

Hi thanks for ur valuable reply.

How to test which signal you can catch with shell ? Here is example script:

#!/bin/ksh  # or bash
sig=0
while (( sig < 30 ))
do
        trap "echo sig:$sig " $sig
        (( sig+=1 ))
done

while true
do
        echo "my pid is $$"
        echo "use: kill -N $$"
        echo " - N is 0-29"
        sleep 60
done

Start this script in background and then use kill to send different signal for this bg process.

---------- Post updated at 06:28 PM ---------- Previous update was at 05:05 PM ----------

Basic trap handling, exit = signal EXIT

realexit() 
{
   echo "int EXIT has done"
}

ctrlc() 
{       
   echo "int INT (ctrl-C)"
   echo "end this script"
   exit
}
        
trap 'realexit' EXIT
trap 'ctrlc' INT 
trap ':' HUP QUIT  # nop - do nothing - process continue

while true
do
    date
    echo "proc:$$"
    sleep 30
done

Start this script in background and send signals using kill
kill -HUP $!
kill -INT $!
kill -QUIT $!
...