killing a child process within a shell

Hi All,
I have a written a script in korn shell for importing data into a oracle database. The shell invokes the import within the script. I want to kill this import (child process) . I tries using trap, but this does not kill the import even if i press cnt c. i have to login into other terminal and run a pkill imp.

How do i kill a child process within a parent using cnt c ?

thanks.

When you press control c, your terminal driver sees that and sends a signal to your processes. To kill one of your process, you need to send the target process a signal. In a shell script this involves the kill command. For example:

#! /usr/bin/ksh
sleep 600 &
pid=$$
sleep 10
kill $pid
exit 0

The first sleep is a background job and we save its pid. After the second sleep, we kill the background job.

Hi,
I tried doing this but still i cannot kill the import using CNTRL C , but now if i use pkill imp using other unix id, the imp gets killed as well as the parent process also. Earlier the imp used to get killed, but the shell kept on executing res of the commands after imp
If i am not clear, i am attaching the script. Please check and let me know what i changes i should make for kill the imp using cntl c or any other interrrupts.
#!/bin/ksh
ORAFIL=/comp/files
trap 'kill $pid;exit' 2 3 15
echo
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo " D A T A B A S E M E N U L I S T "
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 1 " Zim Database "
echo 2 " Zam Database "
echo 7 " Quit "
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo
echo "Please Enter A Number From 1 To 6 To Select A Target Database or 7 to exit
" ; read response
case $response in
1) dbid=prodz
echo "The target database is $dbid"
;;
2) dbid=prodm
echo "The target database is $dbid"
;;
7) exit
;;
esac
echo
echo "Enter the Schema Name From Which Objects Were Exported --";read schfrom
echo
echo "Enter The Schema Name To Which Objects Are To Be Imported -- " ;read schto
echo
echo "Enter The Password For The Schema $schto --" ;read schpass
echo
echo "Enter the Password for Schema SYS --" ;read syspass
echo
echo "Enter The Filename Including The Directory Of The Dump File --" ;read filenam
while [ filename ];do
if [ ! -f $filenam ];then
echo "FileName is Incorrect. Please correct them";read filenam
else
break
fi
done
export ORACLE_SID=$dbid
echo
echo "Are All The Information Entered OK (y/n) ?" ;read confirm
while [ true ]; do
case "$confirm" in
y)
sqlplus -s /nolog << !
connect $schto/$schpass@$dbid
set pages 30000
set linesize 1000
set echo off

	host echo "file=$filenam" &gt; $ORAFIL/import.parfile
	host echo "userid=sys/$syspass" &gt;&gt; $ORAFIL/import.parfile
	host echo "log=/logs/importlogs/$schto\`date "\+%d%m"\`.log" &gt;&gt; $ORAFIL/import.parfile
	host echo "ignore=y" &gt;&gt; $ORAFIL/import.parfile
	host echo "buffer=240000" &gt;&gt; $ORAFIL/import.parfile
	host echo "commit=y" &gt;&gt; $ORAFIL/import.parfile
	host echo "rows=y" &gt;&gt; $ORAFIL/import.parfile
	host echo "fromuser=$schfrom" &gt;&gt; $ORAFIL/import.parfile
	host echo "touser=$schto" &gt;&gt; $ORAFIL/import.parfile
 	host imp parfile=$ORAFIL/import.parfile &
	host pid=$$

	set feedback off
	spool $ORAFIL/ena_trigs.sql
	select 'ALTER TABLE '||table_name ||' ENABLE ALL TRIGGERS ;' from user_triggers;
	spool off
	set feedback on
	@$ORAFIL/ena_trigs.sql

	set feedback off
 	spool $ORAFIL/ena_const.sql
	select 'ALTER TABLE '||table_name ||' ENABLE CONSTRAINT '||constraint_name||';' from user_constraints where status='DISABLED';
	spool off
	set feedback on
	@$ORAFIL/ena_const.sql 
	exit

!
break ;;
n)
echo "Exiting out of the program"
exit ;;
esac
done
echo "Import is Finished. Please check logs for any errors"