Difference between exit () Abort ()

Source: Internet
Author: User

exit () function ends. Program Returns a value to the operating system, informs the program of the final state. After the exit () function is called, the control is handed over to the operating system. Before the end of the program, the exit () function will call all functions previously registered using atexit (), call them in the LIFO order, close all open files, and delete tmpfile () all temporary files created by the function. The
abort () function sends a SIGABRT signal to terminate program execution. The cleanup function registered with the atexit () function is not called. Whether the buffer zone will be cleared is related to the system. As shown in the following figure, it is cleared. But it is not disabled. When the process ends, it closes itself.
(for Ubuntu, The centos test clears the Buffer Zone .)

# Include <signal. h> # include <stdio. h> # include <stdlib. h> # include <unistd. h> voidabort (void)/* POSIX-style abort () function */{sigset_tmask; struct sigactionaction;/** caller can't ignore SIGABRT, if so reset to default. */sigaction (SIGABRT, null, & Action); If (action. sa_handler = sig_ign) {action. sa_handler = sig_dfl; sigaction (SIGABRT, & Action, null);} If (action. sa_handler = sig_dfl) fflush (null);/* flush all open stdio streams * // ** caller can't block SIGABRT; make sure it's unblocked. */sigfillset (& Mask); sigdelset (& Mask, SIGABRT);/* mask has only SIGABRT turned off */sigprocmask (sig_setmask, & Mask, null ); kill (getpid (), SIGABRT);/* send the signal * // ** if we're here, process caught SIGABRT and returned. */fflush (null);/* flush all open stdio streams */action. sa_handler = sig_dfl; sigaction (SIGABRT, & Action, null);/* reset to default */sigprocmask (sig_setmask, & Mask, null);/* just in case... */kill (getpid (), SIGABRT);/* and one more time */exit (1);/* This shoshould never be executed... */}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.