Kill Parent/ Child processes

I am trying to kill PIDs that are tied to a KSH "load_sqlplus" and I am using the below code

 
LIST_PID=`ps -ef | grep -i "load_sqlplus" | grep -v grep | awk '{print $2}'`
if [ "${LIST_PID}" != '' ]; then
    echo "Processes killed" "PID : " $LIST_PID 
    kill -9 $LIST_PID
else
    echo "Nothing to Kill" 
fi

The issue i am facing is there are child processes that are tied to PIDs that falls in the above category and
those are not getting killed.
In other words when i execute the above script I also want to kill any child PIDs associated with the PIDs
getting killed..
Any input will be greatly appreciated

I would be very careful about killing processes that are banging up against a database. Some will argue that you should attempt to kill any process with a TERM or HUP signal before resorting to 'kill -9' as it gives the process a chance to finish gracefully.

That said, if you decide that you still want to kill all of the processes, and any descendants of those processes, that match a pattern, you might have to resort to something like the script below. There might be some 'pstree-like' command out there that does it, but if I knew of one it escapes me at the moment.

#!/usr/bin/env ksh
ps -elf | awk -v me=$$ -v pat=${1:-foo} '
    function printchain( list,      i, a, n )
    {
        n = split( list, a, " " );
        for( i = 1; i <= n; i++ )
        {
            klist = sprintf( "%s%s ", klist, a );
            printchain( childrenof[a] );
        }
    }

    /-v me/ { next; }
    match( $0, pat ) { parents[++pidx] = $4; }  # parent pids to list

    { childrenof[$5] = childrenof[$5] " " $4 }

    END {
        for( i = 1; i <= pidx; i++ )
        {
            klist = parents " ";
            printchain( childrenof[parents] );
            if( !match( " " klist " ", " " me " " ) )
                printf( "kill these: %s\n", klist );
        }
    }
'
exit

The script accepts a pattern to search the output from ps for (be careful, you could easily over match) and lists all of the PIDs that match, and the descendents; one group per line. It tries to be smart about not listing itself or related processes; your milage might vary on whether it is successful at that or not. It should be easy to extend this to actually issue the kill commands, but I'll stay away from posting any such code.

Thanks for the Inuput..Greatly Appreciated

I think the pgrep and pkill commands should be able to help you on your quest. Be careful killing database processes.

Please post what Operating System and version you have and what Shell you are using. Not all have "pgrep", "ptree" or "pkill".

Never ever issue "kill -9" to a process which might be connected to a database. The only exception I know is when you need to forcibly shut down a database where sessions are stuck on I/O (e.g. after a disc failure).

In your case "kill -15" has a good chance of killing the child processes too.
The "kill -9" could easily leave the child process parentless and looping.

Depending on the circumstances it is usually better to use database tools to disconnect a client rather than crashing the process.