在 Linux 中退出时如何注册进程的回调
How do register the callback for process when exit in Linux?
我在 Linux 中创建进程,我需要在进程退出时注册回调?正确的方法是什么?谢谢和问候。
你可以
使用 std::atexit(),以及一个从 cpppreferences 中窃取的示例
#include <iostream>
#include <cstdlib>
void atexit_handler_1()
{
std::cout << "at exit #1n";
}
void atexit_handler_2()
{
std::cout << "at exit #2n";
}
int main()
{
const int result_1 = std::atexit(atexit_handler_1);
const int result_2 = std::atexit(atexit_handler_2);
if ((result_1 != 0) or (result_2 != 0)) {
std::cerr << "Registration failedn";
return EXIT_FAILURE;
}
std::cout << "returning from mainn";
return EXIT_SUCCESS;
}
相关文章:
- boost::进程间消息队列引发错误
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 无法将结构注册为增强几何体3D点
- 是否可以通过C++扩展强制多个python进程共享同一内存
- IPC使用多个管道和分支进程来运行Python程序
- 异常属于C++中的线程还是进程
- 如何使用AngelScript注册SFML Vector2运算符
- WMI检测进程创建事件-c++
- 在遍历处理程序的向量时注册和注销处理程序
- 有没有任务栏API可以立即应用注册表更改
- c++多进程编写一个唯一的文件
- 如何在C++中将函数发送到另一个进程
- 使用QJsEngine在Qt中注册自定义类型
- 进程外 EXE 的免注册 COM
- 某些进程的注册表限制
- 如何在我的进程中运行的二进制文件中注册操作和内核
- 从多个进程和同一进程中注册同一ETW TraceLogging提供程序GUID
- 在 Linux 中退出时如何注册进程的回调
- 具有进程的句柄 如何注册以监视其关闭/重新启动/复制事件
- 如何在进程外客户端中获得免注册的COM对象代理