Не сте регистриран! Регистрирайте се БЕЗПЛАТНО, за да използвате услугите на сайта!

 timelykill - kill process pid after n seconds|minutes|hours|days
Автор  Ext2 (08.11.2004 23:53) съобщение до автора
Погледнат  1975 пъти добави към любими
Оценка добави коментар
Гласове  1 изпрати на приятел
Коментари  (0) абонирай се за Shell
     
Ext2
     
 

#! /bin/bash
  1. ################################################

       NAME_="timelykill"
    PURPOSE_="kill process pid after n seconds|minutes|hours|days"
   SYNOPSIS_="$NAME_ [-hl] <pid> <n>s|m|h|d"
   REQUIRES_="standard GNU commands"
    VERSION_="1.0"
       DATE_="2004-06-20; last update: 2004-07-21"
     AUTHOR_="Dawid Michalczyk <dm@eonworks.com>;"
        URL_="www.comp.eonworks.com"
   CATEGORY_="sys"
   PLATFORM_="Linux"
      SHELL_="bash"
 DISTRIBUTE_="yes"

  1. ###############################################
  2. This program is distributed under the terms of the GNU General Public License

usage () {

echo >&2 "$NAME_ $VERSION_ - $PURPOSE_
Usage: $SYNOPSIS_
Requires: $REQUIRES_
Options:
     <pid> <n>s|m|h|d, pid and n seconds|minutes|hours|days to wait before killing the process
     -h, usage and options (this help)
     -l, see this script"
exit 2
}

  1. local func
check_pid() {

    kill -0 $1 &>/dev/null # using bash kill built in
    [ $? = 0 ] && return 0 || return 1

}

  1. enabling extended globbing
shopt -s extglob

  1. option handling
case $1 in
    -h) usage ;;
    -l) more $0; exit 2 ;;
    +([0-9])) # arg1 can only be an integer

        [ $2 ] || { echo missing second argument, type $NAME_ -h for help; exit 2; }
        check_pid $1 ; [ $? != 0 ] && { echo pid $1 does not exits; exit 2; }
        sleep ${2} # before the kill

        while kill -0 $1 &>/dev/null ;do
             
            kill -15 $1; check_pid; [ $? == 1 ] && exit 0
            kill  -3 $1; check_pid; [ $? == 1 ] && exit 0
            kill  -9 $1; check_pid; [ $? == 1 ] && exit 0
            echo process can not be killed, possibly due to lack of ownership rights
            exit 1

        done ;;

    *) echo invalid or missing argument, type $NAME_ -h for help ; exit 2 ;;

esac



Ключови думи: shell timelykill shell script bin bash process seconds minutes hours days




 1 посетител чете този скрипт (0 потребители и 1 гост)  
Активни потребители: ---
   
  

Еmail  
 

 

 
  • Интересно от Софтуер
 
  • Интересно от myLINKS
 
 
 
 



IT-PLACE.NET © 2004 - 2008