有没有办法在Python改变有效的过程叫什么名字? [英] Is there a way to change effective process name in Python?

查看:115
本文介绍了有没有办法在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"

似乎并没有工作。当我得到进程列表(以 PS AX 在我的Linux盒)的真实姓名不会改变。我preFER一个便携式解决方案(或其他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.

在此先感谢

推荐答案

简单地说,没有可移植的方法。你必须测试系统,并使用preferred方法,该系统。

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.

你的意思是一个服务名称?我presume如此,因为没有别的真正使任何意义(至少在我的非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).

如果是这样,你需要使用添金的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系统调用)。我是pretty确保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天全站免登陆