SHELL program for the Kill process on a UNIX platform, KillProg

xiaoxiao2021-03-06  110

The source program comes from http://www.unixreview.com/documents/urm0108e/

In the original program, the statement that filters out your own process has a bug. If you put KillProg in the path to a $ PATH variable, then starting KillProg from other paths, $ 0 is with a path, then I will change $ 0 to $ {0 ## * /}, you can filter out

Later, I also wrote an email to this author. I want to explore it. Don't care about me, is it that his English is too bad, huh, huh

Under the Korn shell, the source program is as follows:

#! / bin / ksh # killprog: kill a program by name instead of by process id. # i f 'is more than one copy, display a list, and # ask to pick the right one. # Author: fred brunet # modify: GEHONGBIN 2001.8.30 $ 0 => $ {0 ## * /}

Kill = / TMP / KillProgout. $$ if [$ # -eq 0] Then Printf "Usage: KillProg Name / N" EXIT 1FI

# Eliminate Present Program and 'GREP $ 1' from Processps - EF | GREP -V "GREP $ 1" | grep -v $ {0 ## * /} | Grep $ 1> $ KILLCOUNT = `WC -L $ KILL | awk '{ Print $ 1} '`IF [$ count -ge 1] Then awk' {Printf"% 2D:% S / N ", NR, $ 0} '<$ killelse printf" no matches to kill / n "if [-f $ Kill] THEN RM $ KILL FI EXIT 1FIPRINTF "Which of the Above Do You Mean: Enter Number OR '0' To Quit:"

While Truedo Read Lineno # Non-Numeric Data Returns 0 LCNT = `Echo $ LINENO | AWK '{IF ($ 0 ~ / [^ 0-9] /) Print 0 Else Print 1}'` IF [$ LCNT-EQ 0] Then Printf "Valid INPUT: 1- $ Count or '0' to quit. Rener Number:" Continue Fi

# default to 0 and quit lineno = $ {lineno: = 0} IF [$ lineno -eq 0] Then IF [-f $ kill] THEN RM $ KILL FI EXIT 1 FI

IF [$ LINENO -GT $ COUNT -O $ LINENO -LT 0] Then Printf "Valid INPUT: 1- $ Count or '0' to quit. Rener Number:" else break fidoneflist = `sed -n" $ {lineno} P "$ KILL` $ $ flist | awk '{printf"% s / n ", $ 0}' killproc =` echo $ flist | awk '{print $ 2}' `Printf" Kill ($ killproc)? y / n " Read answercase $ ANSWER IN Y | Y) KILL $ KILLPROC Printf "$ KILLPROC TERMINATED! / N" ;; * Printf "nothing killed / n" ;; esacif [-f $ kill] THEN RM $ KILLFI # End KillProg

转载请注明原文地址:https://www.9cbs.com/read-123487.html

New Post(0)