如何在ActiveState Perl中轻轻终止进程? [英] How can I gently kill a process in ActiveState Perl?

查看:167
本文介绍了如何在ActiveState Perl中轻轻终止进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用特定的退出代码吗?

Do I need to use an specific 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);

通过这种方式,它可以杀死Firefox配置文件,但不是很轻而易举.

That way it kills, but not gently, it is generating problems with the Firefox profile.

推荐答案

  Window的taskkill以外的其他常用方法是强制性的.感谢 mob melpomene .

Short   Usual methods other than Window's taskkill are forceful. Thanks to mob and melpomene.

Win32::Process 文档没有说出方法KillKillProcess的作用,但它们对此似乎很直率. Windows确实提供了如何终止进程的等级,例如,请参见优美终止的这篇文章通过winapi ,即使它没有UNIX的信号.但是,模块和kill(请参阅结尾)显然都没有使用它.

The Win32::Process documentation doesn't say what the methods Kill or KillProcess do, but they seem pretty blunt about it. 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. However, this is apparently not utilized by the module nor by kill (see end).

Windows自己的taskkill应该很好地要求进程终止.通过在系统的控制台中运行taskkill /?来查询标志.这是 taskkill on MS technet 的文档.例如,这会通过其$pid及其子项

The Windows's own taskkill should nicely ask the process to terminate. Query it for flags, by running taskkill /? in a console on your system. Here is documentation for taskkill on MS technet. For example, this terminates the process by its $pid, along with its children

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

如果方法GetProcessID()没有返回真实ID,请参见下面的链接以了解其他方式.

If the method GetProcessID() doesn't return the real ID, see the link below for other ways.

我现在无法在Windows上进行测试.第二部分 this post 中有更多相关细节.

I can't test on Windows right now. There's a bit more related detail in this post, second part.

Perl的kill在Windows上显然是强制的.来自 perlport

Perl's kill is apparently forceful on Windows. From perlport

... kill($sig, $pid)终止由$pid标识的进程,并使其以退出状态$sig立即退出.

... kill($sig, $pid) terminates the process identified by $pid, and makes it exit immediately with exit status $sig.

感谢 melpomene 以获得评论和文档链接.

Thanks to melpomene for comment and documentation link.

我相信exitcode仅告诉处理要在退出时向系统报告的内容.

The exitcode, I believe, only tells to process what to report to the system as its exit.

这篇关于如何在ActiveState Perl中轻轻终止进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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