FAQ
Hi ALL,
Looks like off topic, but it can be useful for Oracle administration
purposes on Linux (Unix) platform.

I have need to kill one of my shell scripts in case of timeout is off.
Not just single process but all that is relative to it.

After searching thought net I have wrote my routine.
Looks like there is place for improvement. Can somebody recommend one, or
somebody has more elegant way how to achieve the goal.

#!/bin/bash
# there $1 is pid of the process
v_pforkill=`pstree -p $1 |
awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' |
sort -u |
awk -F"(" '{print $2}' |
awk -F")" '{print $1}' |
sort -u |
awk '{ORS=" "; print $1 }'`
kill -9 $v_pforkill

With all my respects,
Jurijs
+371 9268222 (+2 GMT)

Thank you for teaching me.
http://otn.oracle.com/ocm/jvelikanovs.html

Search Discussions

  • J.Velikanovs_at_alise.lv at Jan 21, 2005 at 4:27 pm
    Hi ALL,
    Looks like off topic, but it can be useful for Oracle administration
    purposes on Linux (Unix) platform.

    I have need to kill one of my shell scripts in case of timeout is off.
    Not just single process but all that is relative to it.

    After searching thought net I have wrote my routine.
    Looks like there is place for improvement. Can somebody recommend one, or
    somebody has more elegant way how to achieve the goal.

    #!/bin/bash
    # there $1 is pid of the process
    v_pforkill=`pstree -p $1 |
    awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' |
    sort -u |
    awk -F"(" '{print $2}' |
    awk -F")" '{print $1}' |
    sort -u |
    awk '{ORS=" "; print $1 }'`
    kill -9 $v_pforkill

    With all my respects,
    Jurijs
    +371 9268222 (+2 GMT)

    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html
  • J.Velikanovs_at_alise.lv at Jan 21, 2005 at 5:53 pm
    Thank you all who pointed me on pkill/pgrep.
    One little inconvenience, which these can’t handle: it is subcalls.
    Lets say my script calling other script and so on.
    For example I have process hierarchy like below
    -sshd,754)
    -sshd,25317)
    `-bash,25547)
    `-su,25597) - cacti
    `-bash,25598)
    -pstree,28688) -ap
    `-sh,28946) ./cron_test.sh
    `-sleep,27900) 20

    I would like to kill all those processes.
    If I run pkill –P 754, just two processes going to be killed (754, 25317).

    Is there better chance to kill them, except I have posted?

    Jurijs
    +371 9268222 (+2 GMT)

    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html

    J.Velikanovs_at_alise.lv
    Sent by: oracle-l-bounce_at_freelists.org
    2005.01.21 22:34
    Please respond to J.Velikanovs


    To: oracle-l_at_freelists.org
    cc:
    Subject: Killing process in Linux with all child processes.

    What is the best way?

    Hi ALL,
    Looks like off topic, but it can be useful for Oracle administration
    purposes on Linux (Unix) platform.

    I have need to kill one of my shell scripts in case of timeout is off.
    Not just single process but all that is relative to it.

    After searching thought net I have wrote my routine.
    Looks like there is place for improvement. Can somebody recommend one, or
    somebody has more elegant way how to achieve the goal.

    #!/bin/bash
    # there $1 is pid of the process
    v_pforkill=`pstree -p $1 |
    awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' |
    sort -u |
    awk -F"(" '{print $2}' |
    awk -F")" '{print $1}' |
    sort -u |
    awk '{ORS=" "; print $1 }'`
    kill -9 $v_pforkill

    With all my respects,
    Jurijs
    +371 9268222 (+2 GMT)

    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html
  • J.Velikanovs_at_alise.lv at Jan 21, 2005 at 6:53 pm
    After short investigation, I have implemented solution below.
    Seems it’s working (as usually no warranty at all).
    #!/bin/bash

    # Before call the routine which possible can hung lets run the killer.sh
    # specifying time out 30 sec and our process pid $$
    /usr/bin/nohup ./killer.sh $$ 30 1>/dev/null 2>&1 &
    # Lets run the routine which can hang
    ./my_possible_hanhing_script.sh


    killer.sh
    #!/bin/bash

    # Check if $1 process finished within timeout then exit else got to
    killing

    # Killing
    v_pforkill_tmp=`pstree -p $1`
    v_pforkill=`echo $v_pforkill_tmp |
    awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' |
    awk -F")" '{print $1}' |

    grep -v killer.sh |
    grep -v pstree |
    sort -u |

    awk -F"(" '{print $2}' |
    awk '{ORS=" "; print $1 }'`

    kill -9 $v_pforkill

    Jurijs
    +371 9268222 (+2 GMT)

    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html

    J.Velikanovs_at_alise.lv
    Sent by: oracle-l-bounce_at_freelists.org
    2005.01.22 00:25
    Please respond to J.Velikanovs


    To: J.Velikanovs_at_alise.lv
    cc: oracle-l_at_freelists.org, oracle-l-bounce_at_freelists.org
    Subject: Re: Killing process in Linux with all child

    processes. What is the best way?

    Thank you all who pointed me on pkill/pgrep.
    One little inconvenience, which these can’t handle: it is subcalls.
    Lets say my script calling other script and so on.
    For example I have process hierarchy like below
    -sshd,754)
    -sshd,25317)
    `-bash,25547)
    `-su,25597) - cacti
    `-bash,25598)
    -pstree,28688) -ap
    `-sh,28946) ./cron_test.sh
    `-sleep,27900) 20

    I would like to kill all those processes.
    If I run pkill –P 754, just two processes going to be killed (754, 25317).

    Is there better chance to kill them, except I have posted?

    Jurijs
    +371 9268222 (+2 GMT)

    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html

    J.Velikanovs_at_alise.lv
    Sent by: oracle-l-bounce_at_freelists.org
    2005.01.21 22:34
    Please respond to J.Velikanovs


    To: oracle-l_at_freelists.org
    cc:
    Subject: Killing process in Linux with all child processes.

    What is the best way?

    Hi ALL,
    Looks like off topic, but it can be useful for Oracle administration
    purposes on Linux (Unix) platform.

    I have need to kill one of my shell scripts in case of timeout is off.
    Not just single process but all that is relative to it.

    After searching thought net I have wrote my routine.
    Looks like there is place for improvement. Can somebody recommend one, or
    somebody has more elegant way how to achieve the goal.

    #!/bin/bash
    # there $1 is pid of the process
    v_pforkill=`pstree -p $1 |
    awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' |
    sort -u |
    awk -F"(" '{print $2}' |
    awk -F")" '{print $1}' |
    sort -u |
    awk '{ORS=" "; print $1 }'`
    kill -9 $v_pforkill

    With all my respects,
    Jurijs
    +371 9268222 (+2 GMT)

    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html
  • J.Velikanovs_at_alise.lv at Jan 24, 2005 at 5:36 pm
    After short investigation, I have implemented solution below.
    Seems it’s working (as usually no warranty at all).
    #!/bin/bash

    # Before call the routine which possible can hung lets run the killer.sh
    # specifying time out 30 sec and our process pid $$
    /usr/bin/nohup ./killer.sh $$ 30 1>/dev/null 2>&1 &
    # Lets run the routine which can hang
    ./my_possible_hanhing_script.sh


    killer.sh
    #!/bin/bash

    # Check if $1 process finished within timeout then exit else got to
    killing

    # Killing
    v_pforkill_tmp=`pstree -p $1`
    v_pforkill=`echo $v_pforkill_tmp |
    awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' |
    awk -F")" '{print $1}' |

    grep -v killer.sh |
    grep -v pstree |
    sort -u |

    awk -F"(" '{print $2}' |
    awk '{ORS=" "; print $1 }'`

    kill -9 $v_pforkill

    Jurijs
    +371 9268222 (+2 GMT)

    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html

    J.Velikanovs_at_alise.lv
    Sent by: oracle-l-bounce_at_freelists.org
    2005.01.22 00:25
    Please respond to J.Velikanovs


    To: J.Velikanovs_at_alise.lv
    cc: oracle-l_at_freelists.org, oracle-l-bounce_at_freelists.org
    Subject: Re: Killing process in Linux with all child

    processes. What is the best way?

    Thank you all who pointed me on pkill/pgrep.
    One little inconvenience, which these can’t handle: it is subcalls.
    Lets say my script calling other script and so on.
    For example I have process hierarchy like below
    -sshd,754)
    -sshd,25317)
    `-bash,25547)
    `-su,25597) - cacti
    `-bash,25598)
    -pstree,28688) -ap
    `-sh,28946) ./cron_test.sh
    `-sleep,27900) 20

    I would like to kill all those processes.
    If I run pkill –P 754, just two processes going to be killed (754, 25317).

    Is there better chance to kill them, except I have posted?

    Jurijs
    +371 9268222 (+2 GMT)

    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html

    J.Velikanovs_at_alise.lv
    Sent by: oracle-l-bounce_at_freelists.org
    2005.01.21 22:34
    Please respond to J.Velikanovs


    To: oracle-l_at_freelists.org
    cc:
    Subject: Killing process in Linux with all child processes.

    What is the best way?

    Hi ALL,
    Looks like off topic, but it can be useful for Oracle administration
    purposes on Linux (Unix) platform.

    I have need to kill one of my shell scripts in case of timeout is off.
    Not just single process but all that is relative to it.

    After searching thought net I have wrote my routine.
    Looks like there is place for improvement. Can somebody recommend one, or
    somebody has more elegant way how to achieve the goal.

    #!/bin/bash
    # there $1 is pid of the process
    v_pforkill=`pstree -p $1 |
    awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' |
    sort -u |
    awk -F"(" '{print $2}' |
    awk -F")" '{print $1}' |
    sort -u |
    awk '{ORS=" "; print $1 }'`
    kill -9 $v_pforkill

    With all my respects,
    Jurijs
    +371 9268222 (+2 GMT)

    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html
  • Jared Still at Jan 21, 2005 at 5:33 pm
    Incorporating pkill may simplify this a bit.

    With -P you can specify a parent process, killing all the children.

    On Fri, 21 Jan 2005 22:26:00 +0200, J.Velikanovs_at_alise.lv
    wrote:
    Hi ALL,
    Looks like off topic, but it can be useful for Oracle administration
    purposes on Linux (Unix) platform.

    I have need to kill one of my shell scripts in case of timeout is off.
    Not just single process but all that is relative to it.

    After searching thought net I have wrote my routine.
    Looks like there is place for improvement. Can somebody recommend one, or
    somebody has more elegant way how to achieve the goal.

    #!/bin/bash
    # there $1 is pid of the process
    v_pforkill=`pstree -p $1 |
    awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' |
    sort -u |
    awk -F"(" '{print $2}' |
    awk -F")" '{print $1}' |
    sort -u |
    awk '{ORS=" "; print $1 }'`
    kill -9 $v_pforkill

    With all my respects,
    Jurijs
    +371 9268222 (+2 GMT)
    ============================================
    Thank you for teaching me.
    http://otn.oracle.com/ocm/jvelikanovs.html

    --
    http://www.freelists.org/webpage/oracle-l
    --
    Jared Still
    Certifiable Oracle DBA and Part Time Perl Evangelist
    --
    http://www.freelists.org/webpage/oracle-l
  • Mladen Gogala at Jan 21, 2005 at 5:49 pm

    J.Velikanovs_at_alise.lv wrote:
    I have need to kill one of my shell scripts in case of timeout is off.
    Murderer!
    Not just single process but all that is relative to it.
    Have you tried with pkill and/or pgrep?

    --
    Mladen Gogala
    Oracle DBA
    Ext. 121

    --
    http://www.freelists.org/webpage/oracle-l

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouporacle-l @
categoriesoracle
postedJan 21, '05 at 4:17p
activeJan 24, '05 at 5:36p
posts7
users3
websiteoracle.com

People

Translate

site design / logo © 2022 Grokbase