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.

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

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...

I'm not sure - try using the Search function on this site and search for "trap signal".

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

Thank you davidg and oombera...