第一个: 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
if (argc != 2) { fprintf(stderr, "Usage: %s \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);