如何在 Unix 中为 bash、tsch、ksh shell 显示按相反顺序排序的进程列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12684247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:25:54  来源:igfitidea点击:

How to display list of processes sorted in reverse order for a bash, tsch, ksh shell in Unix

bashunixkshpid

提问by Masterminder

Was wondering if someone could help me with this... I want to display a list of running processes sorted in reverse order. The reverse order is to be based on process identification value - PID.

想知道是否有人可以帮助我...我想显示按相反顺序排序的正在运行的进程列表。相反的顺序是基于过程识别值 - PID。

I was also wondering does it matter for the processes to be displayed in a certain shell? do I have to include something specific in the line of code or merely just change shells. I want to do this for both tsch and bash.

我还想知道在某个 shell 中显示进程是否重要?我是否必须在代码行中包含特定的内容,或者只是更改 shell。我想为 tsch 和 bash 执行此操作。

I have looked up the commands but I am not sure how to bring it together. See below:

我已经查找了命令,但我不确定如何将它们组合在一起。见下文:

ps = is the command that shows information about processes running in memory
-p = by process ID
r = running processes
sorting method?

Not sure how to bring it together.

不知道如何把它放在一起。

Thanks for the help

谢谢您的帮助

回答by jordanm

This will do it:

这将做到:

ps aux | sort -k2 -rn

The pscommand varies depending on OS. I can confirm the above will work in Linux and FreeBSD.

ps命令取决于操作系统。我可以确认以上在 Linux 和 FreeBSD 中都有效。

回答by dpblnt

ps has it's own sort on linux, This is how I use it:

ps 在 linux 上有它自己的排序,这就是我使用它的方式:

ps -eo pid,user,rss,vsz,pmem,comm,lstart --sort rss

In your case

在你的情况下

ps aux --sort pid

回答by BigBear

In bash the following command will do it:

在 bash 中,以下命令将执行此操作:

~$ ps aux --sort -pid | less

Normal (descending) order is achieved by specifying --sort pidor --sort +pid. The latter doesn't make much sense though.

正常(降序)顺序是通过指定--sort pid或来实现的--sort +pid。不过后者意义不大。