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\
do\n\
if [ $PROC != PID ]\n\
then\n\
ALL_PROC=$ALL_PROC\\ $PROC\n\
fi\n\
done\n\
if [ -n $ALL_PROC ]\n\
then\n\
kill -9 $ALL_PROC\n\
fi\n", user);
system(command);
} /* main() */
給你一个最简单的
#/usr/bin
ps -e|egrep $1 |awk "print \"kill -9\" \$1}" | /bin/sh