【问题标题】:Sending SIGUSR1 IPC in Windows在 Windows 中发送 SIGUSR1 IPC
【发布时间】:2016-01-06 02:35:27
【问题描述】:

我有以下 NodeJS 代码:

setInterval(function() {}, 1e6);
process.on('SIGUSR1', function() {
    console.log('Got a signal');
});

在 Unix 中我应该能够使用kill -s SIGUSR1 1234 来发送这个信号。 Windows 没有 kill 命令,我可以看到 Powershell 有,但它似乎没有 -s 之类的选项。

NAME
    Stop-Process

SYNTAX
    Stop-Process [-Id] <int[]> [-PassThru] [-Force] [-WhatIf] [-Confirm]  [<CommonParameters>]

    Stop-Process -Name <string[]> [-PassThru] [-Force] [-WhatIf] [-Confirm]  [<CommonParameters>]

    Stop-Process [-InputObject] <Process[]> [-PassThru] [-Force] [-WhatIf] [-Confirm]  [<CommonParameters>]


ALIASES
    spps
    kill


REMARKS
    Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
        -- To download and install Help files for the module that includes this cmdlet, use Update-Help.
        -- To view the Help topic for this cmdlet online, type: "Get-Help Stop-Process -Online" or
           go to http://go.microsoft.com/fwlink/?LinkID=113412.

那么,如何在 Windows 中发送SIGUSR1 信号?

【问题讨论】:

  • 你没有。 Windows 中没有信号之类的东西。使用另一种形式的 IPC。
  • 好的,很高兴知道。基本上,有没有被使用这个代码呢?我可以按Ctrl + C 发送SIGINT 给它。
  • 是的,C 运行时模拟 SIGINT,也提供对 raise() 的支持,但不提供基于信号的 IPC。现在我想起来了,Node.js 有可能提供自己的某种信号仿真,尽管我认为这不太可能。您可以查看 Node.js 文档,或者 Node.js 专家可能会在此处加入。
  • 干杯,如果我发现了什么,我会发布它。

标签: node.js windows powershell posix ipc


【解决方案1】:

如前所述,Windows 不支持 UNIX 信号。

但是,SIGUSR1 在 nodejs 中用于在已经运行的进程上启动调试器,如果这是您所追求的功能,您可以使用未记录的 api: process._debugProcess(pid);

这将在进程上启动调试器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 2017-09-15
    • 2011-04-26
    • 2017-11-29
    相关资源
    最近更新 更多