gpt4 book ai didi

perl - 如何在 ActiveState Perl 中温和地终止进程?

转载 作者:行者123 更新时间:2023-12-02 23:24:42 25 4
gpt4 key购买 nike

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

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 配置文件的问题。

最佳答案

简短  除 Window 的 taskkill 之外的常用方法都是强制的。感谢mobmelpomene .

<小时/>

Win32::Process文档没有说明 KillKillProcess 方法的作用,但它们似乎对此非常直率。 Windows 确实提供了如何终止进程的分级,例如,请参阅 graceful termination via winapi 上的这篇文章。 ,即使它没有 UNIX 信号。然而,这显然没有被模块使用,也没有被 kill 使用(见结尾)。

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

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

如果方法GetProcessID()未返回真实ID,请参阅下面的链接了解其他方法。

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

<小时/>

Perl 的 kill 在 Windows 上显然很强大。来自 perlport

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

感谢melpomene获取评论和文档链接。

我相信,exitcode 只告诉处理在退出时向系统报告的内容。

关于perl - 如何在 ActiveState Perl 中温和地终止进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37757264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com