chomp $choice;
if ($choice == 5) {
print "**********************************\n";
print " Enter the User Name\n";
$user_name = <STDN>;
sub kill_processes {
$user_name = <STDN> ;
@process_list = `ps -u $user_name| awk ' { print $2 ;} ' `;
print @process_list;
print "Are you sure you want to kill all of these processes? (Y|N) >";
$resp = <STDIN> ;
chomp $resp;
if ( $resp eq "Y" || $resp eq 'y' ) {
foreach (@process_list) {
if ( ! /PID/ ) {
@process = split / /, $_;
print "Killing Process $process[1]\n";
`kill -09 $process[1]`;
}
}
}
}
}
这只是我无法工作的代码的一部分。当我选择选项 5 时一切正常,但当我输入用户名时它没有任何反应?我怎样才能让它发挥作用?
答案1
嗯...使用已经提供的命令不是更容易吗:
killall -u username
当然,它必须以 root 身份运行。