Child peocess termination.


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Child peocess termination.
# 1  
Old 07-15-2003
Child peocess termination.

Hello all,
Here is the problem:

A ksh script (let's call it abc.sh) gets kicked off from a menu program using "nohup abc.sh &". The process ID of abc.sh can be recieved (pid=$!).

abc.sh runs an Oracle PL/SQL script (it creates a child process).
In order to stop the abc.sh (and the child) in menu program
I can not pass the bellow result to a kill command:

ps -ef|grep -i $pid|grep -iv grep|cut -c 10-15|kill -9 ??????

basically the above line returns the required process IDs (Parent and child) but I can not pass it to kill command. If I could I was free!!!!

If someone knows better way to kill a process along with its children please let know...

An idea: Is it possible to trap the termination signal coming from menu program in abc.sh and stop all the child processes forked from abc.sh in one shot... It's an idea!

Thank you all in advance.
# 2  
Old 07-15-2003
First, I'd say store the PIDs to a variable, since "kill" doesn't seem to be able to have a value piped to it...

ps -ef | grep -i $pid | grep -iv grep | pids=`cut -c 10-15`

Then either:

kill -9 $pids

or try a loop if that doesn't work:

for ID in $pids
do
kill -9 $ID
done
# 3  
Old 07-16-2003
Hi oombera,
Thanks for the tip. It works perfect... I figured another way but I kinda like yours better...

CHILD_P_ID=`echo $CHILD_P_ID |ps -ef| awk '$3 == '$PPID' { print $2 }'`

Another question:
Now I can kill the process and its children. I was just wondering if it is possible to trap the termination signal coming from menu program in abc.sh and do some more stuff like sending a message or something...

Basically I want abc.sh do something when it gets killed through menu program...

I'd appreciate your help...
# 4  
Old 07-16-2003
I'm not sure - try using the Search function on this site and search for "trap signal".
# 5  
Old 07-17-2003
You can of course on your turn exit abc.sh with the $!, right ??

so
kill -9 $pid
newpid=$!

exit $newpid

In your Parent program you can capture this exit status again and re-use it.

Regs David
# 6  
Old 07-17-2003
Thank you davidg and oombera...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Email alert after termination

I am running the gaussian program on UNIX with bash and I want to form a script that will email me once the output life terminates either "normal termination" or "false" I just started learning this last week so could you let me know how to go about this.:b: (13 Replies)
Discussion started by: Jade_Michael
13 Replies

2. AIX

A question about scsi termination

http://ep.yimg.com/ay/iercomputer/ibm-39j5022-ultra320-scsi-adapter-dual-channel-pci-x-fc5736-3.gif I have bought this controller. Simple and fast question: I will put on this controller a external LTO tape,which is terminated with a terminator. I have to put another terminator on PCI-controller... (1 Reply)
Discussion started by: Linusolaradm1
1 Replies

3. Shell Programming and Scripting

Cat termination in script

So, I'm writing a shell script to help automate a process I'm doing. Basically I want to take input from the user for 2 variables, then create a file that consists of: Variable1,Variable2 Constant1 Constant2 .. Constant2000 then run an awk script. I'm pretty new to unix though, and so... (11 Replies)
Discussion started by: Parrakarry
11 Replies

4. Homework & Coursework Questions

Need help with deleting childīs parent and child subprocess

1. The problem statement, all variables and given/known data: I need to make an program that in a loop creates one parent and five children with fork(). The problem i'm trying to solve is how to delete the parent and child of the childīs process. 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: WhiteFace
0 Replies

5. Shell Programming and Scripting

Problem with ssh termination...

hi all, i have a situation where i run ssh command from a unix machine to execute few scripts on 2 other unix machines. my problem is, the scripts that i run will start few commands on the 2 servers and will quit....i am able to quit from the script but i have to give ctrl+c (on the... (10 Replies)
Discussion started by: niteesh_!7
10 Replies

6. Shell Programming and Scripting

Catching the termination of one script

Hi I have a Shell script that needs to execute a command at the End of the excursion of other script And I cant get a handel On the trap command. And that is if the trap command Is the proper way to go this is a extract of the script MYHOST=`hostname| cut -d. -f1` echo $MYHOST ... (4 Replies)
Discussion started by: Ex-Capsa
4 Replies

7. Shell Programming and Scripting

random script termination

I'm writing a script to archive data. First, the files are all rsync'd to the archive directory via NFS mounts(I know not the most efficient, but the only choice in this situation), then I use md5sum to validate the transfers. During execution of the script, it will exit for no apparent reason. It... (6 Replies)
Discussion started by: mph
6 Replies

8. Programming

does snprintf guarantee null termination?

Hi All, I was reading the man page of snprintf function and it saids that snprintf adds a null terminator at the end of the string, but I remember once someone told me that snprintf doesn't guarantee the insertion of a null terminator character. What do you think? Does anyone have experience... (4 Replies)
Discussion started by: lagigliaivan
4 Replies

9. UNIX for Dummies Questions & Answers

Abnormal Termination errors

I'm having trouble with Abnormal Termination errors. What are they, what causes them and how can I prevent them from happening? Are they application specific? (2 Replies)
Discussion started by: bialsibub
2 Replies
Login or Register to Ask a Question