杀死孩子 [英] Killing children

查看:84
本文介绍了杀死孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在编写一个必须生成某些进程的应用程序然后

以后再杀掉它们。

他们正在运行时,它不需要说话或听他们,但有停止和启动按钮和停止

按钮应该停止一切通过开始按钮开始。


在Linux上有很多方法可以做到这一点,但这个项目必须在cygwin下运行
。到目前为止,我在cygwin下完成的唯一工作就是做一个os.system来启动这个过程然后

解析ps输出并使用os.kill来查找ps b / b
找到的进程。这在许多方面都不尽如人意。


我无法让os.spawnl正确启动进程。

我正在使用pexpect,与测试程序一起工作得很好,但不需要生成需要生成的实际流程的
。我做了一点点

玩过程模块,但没有让它工作正常。


有没有人有更好的主意?

-

劳拉( mailto:lc ***** @ laymusic.org, http://www.laymusic.org/

(617)661-8097传真:(501)641-5011

233 Broadway,Cambridge,MA 02139

解决方案

Laura Conrad写道:

我正在编写一个应用程序,必须生成一些进程,然后才能杀死它们后来。它们在运行时不需要说话或听它们,但是有停止和启动按钮,停止
按钮应该停止通过启动按钮启动的所有内容。 br />
在Linux上有很多方法可以做到这一点,但是这个项目必须在cygwin下运行。到目前为止,我在cygwin下完成的唯一工作就是做一个os.system来启动这个过程,然后解析ps。输出并使用os.kill查找ps
找到的进程。这在许多方面都不令人满意。

我无法让os.spawnl正确启动进程。
我使用的是pexpect,它在测试程序中运行良好,但不是
需要生成的实际流程。我做了一点点玩过程的方法。模块,但没有让它正常工作。

有没有人有更好的想法?




这在某些情况下是成功的:


if sys.platform ==''win32'':

def _kill(pid,sig):

'' ''''pid实际上是句柄,但这就是os.spawn *返回的内容

Win32'''''

导入win32api

win32api.TerminateProcess(pid,0)#sign sig,0返回

进程代码

import os

os。 kill = _kill

del _kill

它需要win32api,我不知道这一切将如何工作

cygwin(我不要用)。基本上它允许你以独立于平台的方式使用os.kill()

(前提是你只关心
Linux和Windows NT / XP / 2K ;-)。


-Peter


嗨劳拉,


多么糟糕的主题! ;-)


我有时会使用os.system和pskill
http://www.sysinternals.com/ntw2k/freeware/pskill.shtml - 这应该是

做你想要的。


我从一些产卵变种IIRC获得了我的pid。这应该比通过名称杀死或解析ps输出更可靠(因为你可能

如果有多个进程有相同的话,就会杀死错误的进程

name)。


你的产卵究竟什么不合适?你可以发布你正在使用的产生

电话吗?


干杯,

Stefan

2004年6月6日,19:36,Laura Conrad写道:


我正在编写一个必须生成一些进程的应用程序然后
以后杀了他们。它们在运行时不需要说话或听它们,但是有停止和启动按钮,停止
按钮应该停止通过启动按钮启动的所有内容。 br />
在Linux上有很多方法可以做到这一点,但是这个项目必须在cygwin下运行。到目前为止,我在cygwin下完成的唯一工作就是做一个os.system来启动这个过程,然后解析ps。输出并使用os.kill查找ps
找到的进程。这在许多方面都不令人满意。

我无法让os.spawnl正确启动进程。
我使用的是pexpect,它在测试程序中运行良好,但不是
需要生成的实际流程。我做了一点点玩过程的方法。模块,但没有让它正常工作。

有没有人有更好的主意?
-
劳拉(mailto:lc ***** @ laymusic.org , http://www.laymusic.org/
(617) 661-8097传真:(501)641-5011
233 Broadway,Cambridge,MA 02139

-
http://mail.python.org/mailman/listinfo/python-list

< br $>
// stS@eischet.com //


>>>>> "彼得" == Peter Hansen< pe *** @ engcorp.com>写道:


彼得>在Win32'''''

彼得>进口win32api


彼得>它需要win32api,我不知道这一切将如何工作

Peter> cygwin(我不会用)。


win32api似乎没有出现在cygwin上。

-

劳拉(mailto:lc ***** @ laymusic.org, http:// www .laymusic.org /

(617)661-8097传真:(501)641-5011

233 Broadway,Cambridge,MA 02139


I''m writing an application that has to spawn some processes and then
kill them later. It doesn''t need to talk or listen to them while
they''re running, but there are stop and start buttons and the stop
button should stop everything that gets started by the start button.

There are lots of ways to do this on Linux, but this project has to
run under cygwin. So far, the only thing I''ve gotten to work at all
under cygwin is doing an ''os.system'' to start the process and then
parsing the "ps" output and using os.kill on the processes that ps
finds. This is unsatisfactory in a number of ways.

I have been unable to get os.spawnl to start the processes correctly.
I was using pexpect, which worked fine with test programs, but not
with the actual processes that need to be spawned. I did a little bit
of playing with the "process" module but didn''t get it working right.

Does anyone have a better idea?
--
Laura (mailto:lc*****@laymusic.org , http://www.laymusic.org/ )
(617) 661-8097 fax: (501) 641-5011
233 Broadway, Cambridge, MA 02139

解决方案

Laura Conrad wrote:

I''m writing an application that has to spawn some processes and then
kill them later. It doesn''t need to talk or listen to them while
they''re running, but there are stop and start buttons and the stop
button should stop everything that gets started by the start button.

There are lots of ways to do this on Linux, but this project has to
run under cygwin. So far, the only thing I''ve gotten to work at all
under cygwin is doing an ''os.system'' to start the process and then
parsing the "ps" output and using os.kill on the processes that ps
finds. This is unsatisfactory in a number of ways.

I have been unable to get os.spawnl to start the processes correctly.
I was using pexpect, which worked fine with test programs, but not
with the actual processes that need to be spawned. I did a little bit
of playing with the "process" module but didn''t get it working right.

Does anyone have a better idea?



This has been successful in some cases:

if sys.platform == ''win32'':
def _kill(pid, sig):
''''''pid is actually handle, but that''s what os.spawn* returns on
Win32''''''
import win32api
win32api.TerminateProcess(pid, 0) # ignore sig, 0 is return
code for process
import os
os.kill = _kill
del _kill
It requires win32api, and I don''t know how that all will work with
cygwin (which I don''t use). Basically it lets you use os.kill()
in a platform-independent fashion (provided you care only about
Linux and Windows NT/XP/2K ;-).

-Peter


Hi Laura,

what a terrible subject line! ;-)

I sometimes use os.system with pskill from
http://www.sysinternals.com/ntw2k/freeware/pskill.shtml - this should
do what you want.

I do get my pid from some spawn-variant, IIRC. This should be more
reliable than killing by name or parsing ps output (since you might
kill the wrong process if there are multiple processes with the same
name).

What exactly doesn''t work with your spawning? Could you post the spawn
call you''re using?

Cheers,
Stefan

On 06.08.2004, at 19:36, Laura Conrad wrote:


I''m writing an application that has to spawn some processes and then
kill them later. It doesn''t need to talk or listen to them while
they''re running, but there are stop and start buttons and the stop
button should stop everything that gets started by the start button.

There are lots of ways to do this on Linux, but this project has to
run under cygwin. So far, the only thing I''ve gotten to work at all
under cygwin is doing an ''os.system'' to start the process and then
parsing the "ps" output and using os.kill on the processes that ps
finds. This is unsatisfactory in a number of ways.

I have been unable to get os.spawnl to start the processes correctly.
I was using pexpect, which worked fine with test programs, but not
with the actual processes that need to be spawned. I did a little bit
of playing with the "process" module but didn''t get it working right.

Does anyone have a better idea?
--
Laura (mailto:lc*****@laymusic.org , http://www.laymusic.org/ )
(617) 661-8097 fax: (501) 641-5011
233 Broadway, Cambridge, MA 02139
--
http://mail.python.org/mailman/listinfo/python-list


// st****@eischet.com //


>>>>> "Peter" == Peter Hansen <pe***@engcorp.com> writes:

Peter> on Win32''''''
Peter> import win32api

Peter> It requires win32api, and I don''t know how that all will work with
Peter> cygwin (which I don''t use).

win32api doesn''t seem to be there on cygwin.
--
Laura (mailto:lc*****@laymusic.org , http://www.laymusic.org/ )
(617) 661-8097 fax: (501) 641-5011
233 Broadway, Cambridge, MA 02139


这篇关于杀死孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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