当前位置: 技术问答>linux和unix
不显示删除回复显示所有回复显示星级回复显示得分回复 诚心请教Linux一道面试题(shell编程)
来源: 互联网 发布时间:2016-07-14
本文导语: 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 use...
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”.
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”.
|
这个可以
ps -A u --noheading | awk '{count[$1]++}; END {for (user in count) print user, count[user] | "sort -n -k 2"}' | tail -n3
ps -A u --noheading | awk '{count[$1]++}; END {for (user in count) print user, count[user] | "sort -n -k 2"}' | tail -n3
|
这个应该可以吧。
#!/usr/bin/perl -w
#取得进程
my @list=`ps aux`;
#取得进程用户名
foreach(@list){
my @line=split(' ',$_);
$_=$line[0];
}
#统计个数
my %top;
my $count=@list;
for($i=1;$i
#!/usr/bin/perl -w
#取得进程
my @list=`ps aux`;
#取得进程用户名
foreach(@list){
my @line=split(' ',$_);
$_=$line[0];
}
#统计个数
my %top;
my $count=@list;
for($i=1;$i