简体   繁体   English

如何在ActiveState Perl中轻轻杀死进程?

[英]How can I gently kill a process in ActiveState Perl?

Do I need to use an specific exitcode ? 我需要使用特定的exitcode吗?

Win32::Process::Create(
    $ProcessObj,
    "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe",
    "firefox -no-remote -P $prof_name",
    0,
    NORMAL_PRIORITY_CLASS,
".")|| die ErrorReport();
$ProcessObj->kill(0);

That way it kills, but not gently, it is generating problems with the Firefox profile. 这样就可以杀死它,但不是轻微的,它会导致Firefox配置文件出现问题。

Short Usual methods other than Window's taskkill are forceful. 除了Window的taskkill之外的简短常用方法是有力的。 Thanks to mob and melpomene . 感谢暴徒melpomene


The Win32::Process documentation doesn't say what the methods Kill or KillProcess do, but they seem pretty blunt about it. Win32::Process文档没有说明KillKillProcess所做的方法,但它们看起来相当直率。 Windows does provide a gradation in how to terminate a process, see for example this post on graceful termination via winapi , even as it does not have UNIX's signals. Windows确实提供了如何终止进程的渐变,例如, 通过winapi查看关于正常终止的帖子,即使它没有UNIX的信号。 However, this is apparently not utilized by the module nor by kill (see end). 然而,这显然没有被模块使用,也没有被kill (见最后)。

The Windows's own taskkill should nicely ask the process to terminate. Windows自己的taskkill应该很好地要求进程终止。 Query it for flags, by running taskkill /? 通过运行taskkill /?查询标志taskkill /? in a console on your system. 在您系统的控制台中。 Here is documentation for taskkill on MS technet . 这是taskkill on MS technet文档。 For example, this terminates the process by its $pid , along with its children 例如,这会通过$pid及其子项终止进程

my $pid = $ProcessObj->GetProcessID();
system("taskkill /t /pid $pid");

If the method GetProcessID() doesn't return the real ID, see the link below for other ways. 如果方法GetProcessID()未返回实际ID,请参阅下面的链接以了解其他方法。

I can't test on Windows right now. 我现在无法在Windows上测试。 There's a bit more related detail in this post , second part. this post有更多相关细节,第二部分。


Perl's kill is apparently forceful on Windows. 在Windows上,Pe​​rl的kill显然是有力的。 From perlport 来自perlport

... kill($sig, $pid) terminates the process identified by $pid , and makes it exit immediately with exit status $sig . ... kill($sig, $pid)终止由标识的进程$pid ,并使其与退出状态立即退出$sig

Thanks to melpomene for comment and documentation link. 感谢melpomene的评论和文档链接。

The exitcode , I believe, only tells to process what to report to the system as its exit. 我相信, exitcode只会告诉处理向系统报告的内容。

As far as i know in Perl you could just do 据我所知,在Perl你可以做到

kill -15 (pid)

Who gently kills a process in perl 谁轻轻地杀死了perl中的进程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM