650) this. width = 650; "border =" 0 "src =" http://www.bkjia.com/uploads/allimg/131228/1644131507-0.gif "style =" padding: 0px; margin: 0px; vertical-align: top; border: none; "alt =" "/> process_stopper.zip
#! /Bin/sh
# Http://code.google.com/p/mooon
# Stop a process with a specified name
# Features:
#1. Only processes under the current user name will be stopped
#2. You can specify the command line parameters and execute the command to stop accurately.
# Check Parameters
# Parameter 1: name of the process to be stopped or its complete command line or part of command line
If test $ #-ne 1; then
Printf "\ 033 [1; 33 musage: $0 process_cmdline \ 033 [m \ n"
Exit 1
Fi
Process_cmdline = $1 # process name or process running command line
Cur_user = 'whoam' # current user
Uid = 'id-u $ cur_user '# user id
# Obtain the process name
Process_name = $ (basename 'echo "$ process_cmdline" | cut-d ""-f1 ')
# Obtain the process ID list
Pid_set = 'ps-C "$ process_name" h-o euser, pid, args | awk '{if ($1 = uid | $1 = cur_user) & match ($0, process_cmdline) printf ("% s \ n", $2);} 'uid = $ uid cur_user = $ cur_user process_cmdline = "$ process_cmdline "'
# Kill all processes cyclically
For pid in $ pid_set
Do
# Echo $ pid; exit; # Test
Kill $ pid # Start SIGTERM Signal
Sleep 2 # Send a SIGKILL signal after 2 seconds
Kill-9 $ pid
Done
This article is from the "Fei Yue" blog, please be sure to keep this source http://mooon.blog.51cto.com/1246491/961289