Vintage appMaker의 Tech Blog

우분투에서 프로세스 죽이기 - bash 본문

Source code or Tip/Linux

우분투에서 프로세스 죽이기 - bash

VintageappMaker 2020. 12. 4. 17:45

 

 

VintageAppMaker/processkill_bash

process 죽이기 bash 예제. Contribute to VintageAppMaker/processkill_bash development by creating an account on GitHub.

github.com

간단한 프로세스 죽이기 스크립트 소스. 

#!/bin/bash
print_msg()
{
    colors=("\e[1;32;40m$1\033[0m" "\e[1;32;45m$1\033[0m" "\e[1;34;48m$1\033[0m")
    echo -e ${colors[$2]}
}

# parameter 채크하기
if [ $# -lt 1 ]; then echo -e "uses: $0 \e[1;32;40m[process name]\033[0m"; exit; fi

#구분자를 캐리지리턴으로 한다.
OLDIFS=$IFS
IFS='
'
plist=$(ps -A | grep $1)

numlist=()
count=1
for indx in ${plist[@]}
do
    print_msg "$count) $indx" 0
    IFS=$OLDIFS
    n=$(echo $indx | awk '{print $1}')
    numlist[$count]=$n
    ((count++))
done

size=${#numlist[@]}

if [ $size -eq 0 ]
then
    echo -e "($1) is not founded."
    exit
fi

print_msg "choice you want to kill process." 2
read n

# null 채크한다.
if [ -z $n ]; then exit; fi

# 문자인지 숫자인지 채크한다. 1이면 문자.
let $n; rst=$?
if [ $rst -eq 1 ]; then exit; fi

# 배열범위를 넘어서는지 채크한다.
if [ $n -gt $size ]; then exit; fi

kill ${numlist[$n]}

'Source code or Tip > Linux' 카테고리의 다른 글

linux bash 정리  (0) 2020.07.18
linux bash에서 logcat 사용하기 - Android  (0) 2020.07.16
Comments