怎么办SIGKILL后清理? [英] How to do a cleanup after SIGKILL?

查看:151
本文介绍了怎么办SIGKILL后清理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,它使用共享内存的程序。所述程序的多个实例要么连接到现有的或重新创建它,并给它回OS时,有没有其他进程或只是分离,并终结。我想用一个简单的计数器来跟踪多少进程使用它。

I'm working on a program which uses shared memory. Multiple instances of said program will either connect to an existing one or create it anew, and give it back to OS when there are no other processes or just detach it and terminate. I thought of using a simple counter to keep track of how many processes use it.

我用的atexit()函数来完成清理,但据我所知,在收到SIGKILL信号,进程将不会做任何清理,因此,如果任何的这些流程通常不会终止,我可能永远无法清理内存。

I'm using atexit() function to do the cleanup, however, afaik, upon receiving SIGKILL signal, processes won't do any cleanup, so if any of those processes don't terminate normally, I might never be able to clean the memory.

有没有指定即使SIGKILL信号后做什么办法?我可能会写类似计时器一些机制来检查过程仍然活着,但我真的想避免,如果有另一种方式。

Is there a way to specify what to do even after a SIGKILL signal? I'm probably going to write some mechanism similar to a timer to check if processes are still alive, but I'd really like to avoid it if there is another way.

推荐答案

没有,SIGKILL不能以任何方式您的应用程序捕获 - 如果可能,应用程序可以忽略它,它会破坏它的目的

No, SIGKILL cannot be caught in any way by your application - if it could, the application could ignore it, which would defeat its purpose.

这篇关于怎么办SIGKILL后清理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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