killing a child process within a shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting killing a child process within a shell
# 1  
Old 06-25-2003
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.
# 2  
Old 06-26-2003
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.
# 3  
Old 06-27-2003
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" > $ORAFIL/import.parfile
host echo "userid=sys/$syspass" >> $ORAFIL/import.parfile
host echo "log=/logs/importlogs/$schto`date "+%d%m"`.log" >> $ORAFIL/import.parfile
host echo "ignore=y" >> $ORAFIL/import.parfile
host echo "buffer=240000" >> $ORAFIL/import.parfile
host echo "commit=y" >> $ORAFIL/import.parfile
host echo "rows=y" >> $ORAFIL/import.parfile
host echo "fromuser=$schfrom" >> $ORAFIL/import.parfile
host echo "touser=$schto" >> $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"


Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Child killing parent process and how to set up SMF

Hello, A little background on what we are doing first. We are running several applications from a CLI, and not all of them are fully functional. They do on occasion core dump, not a problem. We are running a service that takes a screen scrape of those apps and displays them in a more user... (5 Replies)
Discussion started by: Bryan.Eidson
5 Replies

2. Programming

Killing a Child Thread

What is the best way for a parent to kill a child thread that has blocked on a command it cannot finish and will never read another line of its code? Will pthread_cancel() work with a thread that will never stop processing its current line of code? Thanks. (4 Replies)
Discussion started by: Brandon9000
4 Replies

3. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

4. UNIX for Dummies Questions & Answers

Killing the shell Process

I was just playing with the processes and suddenly a question striked my mind: What will happen if we kill directly the shell process?? :rolleyes: Do anyone know? Will the system shutdown? Or the system wont let it be killed? (5 Replies)
Discussion started by: paras.oriental
5 Replies

5. Red Hat

Killing child daemon started by parent process

Hi All, Hope this is right area to ask this question. I have a shell script (bash) "wrapper.sh", which contains few simple shell command which executes a "server.sh" (conatins code to execute a java server) as a daemon. Now what I want to kill this "server.sh" so that the server should... (2 Replies)
Discussion started by: jw_amp
2 Replies

6. Shell Programming and Scripting

Newbie Question: Killing a process using a supplied name to a shell script

Hi, I am trying to automate the killing of named processes of which I found a good solution here on the forums but as I am pretty much a begginer to linux I am having an issue. The code I found is: kill $(ps -ef | nawk '/monitoreo start/ { print $2}'} but what I want to do is replace... (3 Replies)
Discussion started by: TylrRssl1
3 Replies

7. UNIX for Advanced & Expert Users

Child Killing Parent

Hi all, I am writing a script which calls other third party scripts that perform numerous actions. I have no control over these scripts. My problem is, one of these scripts seems to execute and do what it is meant to do, but my calling / parent script always exits at that point. I need to... (4 Replies)
Discussion started by: mark007
4 Replies

8. UNIX for Advanced & Expert Users

killing all child processes

Hi, Is there a way I can kill all the child processes of a process, given its process id. Many thanks in advance. J. (1 Reply)
Discussion started by: superuser84
1 Replies

9. Shell Programming and Scripting

Killing child process in ksh

I have a script that (ideally) starts tcpdump, sleeps a given number of seconds, then kills it. When I do this for 10 seconds or and hour, it works fine. When I try it for 10 hours (the length I actually want) it just doesn't die, and will actually stick around for days. Relevant part of my... (1 Reply)
Discussion started by: upnix
1 Replies

10. Shell Programming and Scripting

killing a child process

I am calling another script from my main script and making it run in the background,based upon the value of the input provided by the user I want to kill the child process ,I have written this code timer.ksh & PID=$$ print "\n Do you wish to continue .. (Y/N) : \c " read kill_proc if ]... (4 Replies)
Discussion started by: mervin2006
4 Replies
Login or Register to Ask a Question