什么时候abort()比exit()更受青睐? [英] When abort() is preferred over exit()?

查看:211
本文介绍了什么时候abort()比exit()更受青睐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道两者之间的区别.值得注意的是,abort()发送SIGABRT信号,因此当您的软件依赖它们时,这可能是相关的.但是对于典型的应用程序,exit()似乎是abort()的更安全的版本...?还有其他需要使用abort()而不是exit()的问题吗?

I know the differences between the two. One notable thing is that abort() sends SIGABRT signal, so it may be relevant when your software relies on them. But for a typical application exit() seems to be more safe version of abort()...? Are there any other concerns to use abort() instead of exit()?

推荐答案

如果用户启用了核心转储,则使用abort将转储核心.因此,根据经验,如果您不确定发生了什么问题,那么我将使用abort,获取有关它的有用信息的唯一方法是通过分析核心转储.

Using abort will dump core, if the user has core dumps enabled. So as a rule of thumb, I'd use abort if you're so unsure about what's gone wrong that the only way to get useful information about it is by analysing a core dump.

如果您可以从任意给定位置安全地exit,并且不需要核心转储,那么退出是一种更好的方法.

If you can safely exit from any given point, and don't need the core dump, then exit is a nicer approach.

这篇关于什么时候abort()比exit()更受青睐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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