有没有办法在 Python 中更改有效的进程名称? [英] Is there a way to change effective process name in Python?

查看:35
本文介绍了有没有办法在 Python 中更改有效的进程名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以更改 Python 脚本的有效进程名称吗?我想在获取系统进程列表时显示不同的名称而不是进程的真实名称.在 C 中我可以设置

Can I change effective process name of a Python script? I want to show a different name instead of the real name of the process when I get the system process list. In C I can set

strcpy(argv[0],"othername");

但是在 Python 中

But in Python

argv[0] = "othername"

似乎不起作用.当我获得进程列表(在我的 linux 框中使用 ps ax)时,真实名称不会改变.如果存在,我更喜欢便携式解决方案(或者一种适用于 posix 的解决方案和另一种适用于 Windows 环境的解决方案).

doesn't seem to work. When i get process list (with ps ax in my linux box) the real name doesn't change. I prefer a portable solution (or else one solution for posix and another for windows environments), if it exists.

提前致谢

推荐答案

简单地说,没有可移植的方式.您必须对系统进行测试并使用该系统的首选方法.

Simply put, there's no portable way. You'll have to test for the system and use the preferred method for that system.

此外,我对 Windows 上的进程名称的含义感到困惑.

Further, I'm confused about what you mean by process names on Windows.

您是说服务名称吗?我认为是这样,因为其他任何东西都没有任何意义(至少对我使用大脑的非 Windows 用户而言).

Do you mean a service name? I presume so, because nothing else really makes any sense (at least to my non-Windows using brain).

如果是这样,您需要使用 Tim Golden 的 WMI 接口并调用 .Change 方法服务......至少根据他的教程.

If so, you need to use Tim Golden's WMI interface and call the .Change method on the service... at least according to his tutorial.

对于 Linux,除了 这个打包不当的模块 之外,我发现的所有方法均无效argv[0] 给你.

For Linux none of the methods I found worked except for this poorly packaged module that sets argv[0] for you.

我什至不知道这是否适用于 BSD 变体(它有一个 setproctitle 系统调用).我很确定 argv[0] 在 Solaris 上不起作用.

I don't even know if this will work on BSD variants (which does have a setproctitle system call). I'm pretty sure argv[0] won't work on Solaris.

这篇关于有没有办法在 Python 中更改有效的进程名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆