bash 顶部的进程命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/590952/
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-09 17:58:42  来源:igfitidea点击:

A process command in top

linuxbashprocessutilitiestop-command

提问by Cheery

The problem comes up when you run couple of python scripts. in top at command, it shows only 'python' with these scripts. How to rename a process or otherwise tag it so that I could tell them apart in top?

当您运行几个 python 脚本时会出现问题。在命令的顶部,它只显示带有这些脚本的“python”。如何重命名进程或以其他方式标记它以便我可以在顶部区分它们?

回答by Wookai

Simply use the --full-commandsoption to show the full command line for each process :

只需使用该--full-commands选项来显示每个进程的完整命令行:

top -c

回答by Douglas Leeder

Press "c" and display the command-line - that will allow you to see what they are.

按“ c”并显示命令行 - 这将允许您查看它们是什么。

回答by Jeremy L

You might also check out the ps command. Depending on your system:

您还可以查看 ps 命令。根据您的系统:

ps aux

or

或者

ps -fu USERNAME

回答by Johannes Weiss

Do you search for a way to display the full command line? Then simply press 'c'

您是否正在寻找一种显示完整命令行的方法?然后只需按“ c

回答by chaos

This is probably going to be platform and version dependent, but on the platforms I use (CentOS, Debian), top normally displays the last part of the command run as the ID.

这可能取决于平台和版本,但在我使用的平台(CentOS、Debian)上,top 通常显示作为 ID 运行的命令的最后一部分。

I'm guessing, therefore, that you're running your scripts by doing "python scriptname".

因此,我猜测您是通过执行“python scriptname”来运行脚本的。

If you change your scripts to being executable as themselves (chmod +x and first line #!/usr/bin/python [or wherever python lives]), and then run them using just "scriptname" rather than "python scriptname", they should show up in top as their filename.

如果您将脚本更改为自己可执行(chmod +x 和第一行 #!/usr/bin/python [或 python 所在的任何地方]),然后仅使用“ scriptname”而不是“python scriptname”运行它们,它们应该显示在顶部作为他们的文件名。

回答by aks

You can also try ps aux or ps -au USESRNAME. ps is quite nice since you can format the output, eg. ps -u USERNAME -o pid,command which would display pid and command of the process. Then you can also filter it through grep (ps -u USERNAME -o pid,command|grep python) to see all the running python scripts.

您也可以尝试 ps aux 或 ps -au USESRNAME。ps 非常好,因为您可以格式化输出,例如。ps -u USERNAME -o pid,command 显示进程的pid和命令。然后你也可以通过grep(ps -u USERNAME -o pid,command|grep python)过滤,查看所有正在运行的python脚本。

回答by slacy

I'm not sure if you can do this in Python, but in C programs, argv[0] can actually be modified to show a "prettier" name for the process. I think the constraint is that the new name has to be equal or shorter in length than the original name, such that you don't stomp on memory.

我不确定您是否可以在 Python 中执行此操作,但在 C 程序中,实际上可以修改 argv[0] 以显示该进程的“更漂亮”的名称。我认为限制是新名称的长度必须等于或短于原始名称,这样您就不会占用内存。