如果我运行以下命令:
Process.kill "KILL", pid
Process.wait pid
raise "application did not exit" if not $?.exited?
raise "application failed" if not $?.success?
我得到的错误“应用程序没有退出”。为什么Process.wait
没有在等待?更确切地说,为什么Process.wait
将$?
设置为未退出状态?
如果我运行以下命令:
Process.kill "KILL", pid
Process.wait pid
raise "application did not exit" if not $?.exited?
raise "application failed" if not $?.success?
我得到的错误“应用程序没有退出”。为什么Process.wait
没有在等待?更确切地说,为什么Process.wait
将$?
设置为未退出状态?
该进程在收到kill信号后立即退出,因此Process.wait会立即将相应的Process :: Status对象分配给$?并允许执行继续。流程::状态#退出?只有当进程正常退出时才返回true,所以你看到的是预期的行为 - SIGKILL通常不会导致正常的终止。
从Process::Status
文档:
Posix的上使用一个16位的整数 处理系统记录信息。较低的位记录过程状态(已停止,已退出 ,发信号为),高位可能包含其他 信息。
exited
的状态将意味着该过程本身退出(过程称为exit()
)。但是,由于您强行终止了该进程,因此它将具有signaled
的状态,这意味着由于未被捕获的信号而退出进程(本例中为KILL
)。