if test $# -eq 0
then
echo "Usage: killproc procname"
exit 0
fi
for i
do ps -ea | awk -v name=$i '
BEGIN {
n = 0;
}
$4 == name && !system("kill -9 " $1) {
print $1, "killed"
n ++
}
END {
if (n == 0)
print "No process killed !"
else
print "Kill", n, name, "process !"
}'
done
我也有一个
它是 杀同一有户的
它的作者是::MARTIN .P
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
char *prog,
*user,
command[1024],
*strrchr();
if ((prog = strrchr(argv[0], '/')) == 0)
prog = argv[0];
else
prog++;
if (argc != 2) {
fprintf(stderr, "Usage: %s <user>n", prog);
exit(1);
}
user = argv[1]
setuid(0);
setgid(0);
/* There is a better way but this is easy to program. */
sprintf(command, "
ALL_PROC=''n
for PROC in `ps -u%s | cut -c-6`n
don
if [ $PROC != PID ]n
thenn
ALL_PROC=$ALL_PROC $PROCn
fin
donen
if [ -n $ALL_PROC ]n
thenn
kill -9 $ALL_PROCn
fin", user);
system(command);
} /* main() */
給你一个最简单的
#/usr/bin
ps -e|egrep $1 |awk "print "kill -9" $1}" | /bin/sh
标签: