不显示删除回复显示所有回复显示星级回复显示得分回复 诚心请教Linux一道面试题(shell编程)

tangxiang1981 2009-11-08 05:18:08
Linux scripting
Write a Linux script (language of your choice, to be executed on a modern Linux distribution) that reports the top 3 users on the system with the most number of processes. Print the result to the terminal standard out, one user per line, in no particular order. Kindly put the solution in a file called “top3users.sh”.
...全文
79 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cuijie_cn 2009-11-09
  • 打赏
  • 举报
回复
学习一下
steptodream 2009-11-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 be9809b8 的回复:]
这个可以
ps -A u --noheading | awk '{count[$1]++}; END {for (user in count) print user, count[user] | "sort -n -k 2"}' | tail -n3

[/Quote]
这个绝对可以
wangqingshui531 2009-11-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 be9809b8 的回复:]
这个可以
ps -A u --noheading | awk '{count[$1]++}; END {for (user in count) print user, count[user] | "sort -n -k 2"}' | tail -n3

[/Quote]

你狠!值得学习!
  • 打赏
  • 举报
回复
列出3个用户及他们的子进程?
hlwang_1984 2009-11-08
  • 打赏
  • 举报
回复
学习
hecha 2009-11-08
  • 打赏
  • 举报
回复
这个可以
ps -A u --noheading | awk '{count[$1]++}; END {for (user in count) print user, count[user] | "sort -n -k 2"}' | tail -n3
jeff_jian 2009-11-08
  • 打赏
  • 举报
回复
这个应该可以吧。

#!/usr/bin/perl -w

#取得进程
my @list=`ps aux`;

#取得进程用户名
foreach(@list){
my @line=split(' ',$_);
$_=$line[0];
}

#统计个数
my %top;
my $count=@list;
for($i=1;$i<$count;$i++){
$top{$list[$i]}++;
}

my @name;
my @num;
$count=0;
foreach (keys %top){
#输出统计的
#print $_ . ": " . "$top{$_}\n";
$name[$count]=$_;
$num[$count]=$top{$_};
$count++;
}

#输出TOP 3
my $i;
for ($i=0;$i<3;$i++){
$max=&max(@num);
$num[$max]=-1;
print $name[$max]."\n";
}

sub max{
my @list=@_;
my $len=@list;
my $max=0;
my $i;

for($i=0;$i<$len;$i++){
if($list[$i]>$list[$max]){
$max=$i;
}
}
return $max;
}

19,613

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧