如何在 Rust 中捕捉信号 [英] How to catch signals in Rust

查看:65
本文介绍了如何在 Rust 中捕捉信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一些代码来捕捉像 SIGTERM 这样的信号.

I'm trying to write some code that will catch a signal like SIGTERM.

我发现了这个 我还发现了 如何在 Rust 中处理阻塞的 i/o,或一般情况下长时间运行的外部函数调用.

I found this and I also found How to handle blocking i/o in Rust, or long running external function calls in general.

但是在当前的 Rust 版本(每晚 0.12)中,std::io::signal::Listener 似乎被删除了.是不是放在别的地方了?如果是这样,有人可以指出我如何捕捉信号吗?

But in the current Rust version (0.12 nightly) it seems like that std::io::signal::Listener was removed. Did it get put somewhere else? If so can someone point me to how to catch a signal?

推荐答案

我相信 std::io::signal 模块在 这个 拉取请求.据称,本机运行时从未正确实现正确的信号处理,因此您现在可能无法使用它.似乎是此问题的跟踪问题.

I believe that std::io::signal module was removed in this pull request. It is claimed that proper signals handling was never implemented properly for native runtime, so you likely wouldn't be able to use it now anyway. This seems to be a tracking issue for this problem.

与此同时,我认为您必须从 libc 降到最低级别的不安全函数.

In the meantime, I think, you will have to drop down to the lowest-level unsafe functions from libc.

这篇关于如何在 Rust 中捕捉信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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