Saturday, June 29, 2013

Killing child process in Linux

I had requirement to stop one of your stats collection process at 7 AM, the stats collection was running from one .sh file which was running a .sql file to collect stats.so, to kill entire process i had to find child process (here child process is .sql file).

I searched through the internet and found various tricks to do it, but most of them seems to be not supporting in my bash version. it tried it myself ,here is the code which is working for me.


export xpid2=`ps -ef|grep -v grep|grep collect_daily_stats2|awk '{print $2}'`
echo "parent:"$xpid2
export cpid2=`ps -ef|grep -v grep|grep "$xpid2"|awk '{print $2}'|sed -s '1d'`
echo "child:"$cpid2
kill -9 "$cpid2"
echo "daily stats2 stopped"
 mailx -s"Daily stats2 stopped successfully" teradatamanager@cvscaremark.com  < /dev/null
else


any suggestions are welcome.

No comments:

Post a Comment