顶部的进程命令
当您运行几个 python 脚本时就会出现问题。 在命令的顶部,它仅显示带有这些脚本的“python”。 如何重命名进程或以其他方式标记它以便我可以在顶部区分它们?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您还可以查看 ps 命令。 取决于您的系统:
或
You might also check out the ps command. Depending on your system:
or
您是否正在寻找一种显示完整命令行的方法? 然后只需按“
c
”Do you search for a way to display the full command line? Then simply press '
c
'这可能与平台和版本相关,但在我使用的平台(CentOS、Debian)上,top 通常将命令运行的最后部分显示为 ID。
因此,我猜测您正在通过执行“python scriptname”来运行脚本。
如果您将脚本更改为本身可执行(chmod +x 和第一行 #!/usr/bin/python [或 python 所在的任何地方]),然后仅使用“scriptname”运行它们与“python scriptname”相比,它们应该作为文件名显示在顶部。
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.
I'm guessing, therefore, that you're running your scripts by doing "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.
您还可以尝试 ps aux 或 ps -au USESRNAME。 ps 非常好,因为您可以格式化输出,例如。 ps -u USERNAME -o pid,command 将显示进程的 pid 和命令。 然后你还可以通过 grep (ps -u USERNAME -o pid,command|grep python) 过滤来查看所有正在运行的 python 脚本。
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.
我不确定是否可以在 Python 中执行此操作,但在 C 程序中,实际上可以修改 argv[0] 以显示进程的“更漂亮”名称。 我认为限制是新名称的长度必须等于或小于原始名称,这样您就不会占用内存。
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.
按“
c
”并显示命令行 - 这将允许您查看它们是什么。Press "
c
" and display the command-line - that will allow you to see what they are.只需使用
--full-commands
选项即可显示每个进程的完整命令行:Simply use the
--full-commands
option to show the full command line for each process :