Welcome, guest | Sign In | My Account | Store | Cart

kill a group of process within the same name

Bash, 19 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

if [[ $# -ne 1 ]];then
    echo "process name?"
    exit 0
fi

all=`ps -A|grep $1`
for i in $all
do
    p=`echo $i |grep -x -o -E "[0-9]+"`
    if [[ -z $p ]]; then
        continue
    fi

    sudo kill $p
done

ps -A|grep $1

1 comment

ccpizza 12 years, 5 months ago  # | flag

why don't you use pgrep?

Created by J Y on Wed, 17 Jun 2009 (MIT)
Bash recipes (41)
J Y's recipes (21)

Required Modules

  • (none specified)

Other Information and Tasks