Exit functions in C

前端 未结 4 837
礼貌的吻别
礼貌的吻别 2021-01-17 23:40

What is the difference between exit(), _exit() and _Exit() in C?

How do I decide which to use?

On bash, <

4条回答
  •  臣服心动
    2021-01-18 00:05

    Normative in C99 are exit and _Exit.

    The difference between the two is that exit also executes the handlers that may be registered with atexit and closes streams etc whereas _Exit doesn't call the atexit routines and may or may not close streams properly.

    _exit is from POSIX and has similar properties as _Exit with the difference that it is guaranteed to close streams properly.

    In summary, whenever you can you should use exit, this is the cleanest way to terminate.

提交回复
热议问题