I was reading the man page for abort()
system call and I came across this.
RETURN VALUE
The
abort()
function never returns.
I was wondering how this is possible?
Calling the abort
function results in the program being terminated.
Therefore, abort
does not return.
A number of C library functions never return to their caller:
exit()
terminates the program, providing an exit status.
abort()
terminates the program with an error message.
longjmp()
transfers control back to the point saved by the corresponding setjmp()
The assembly code either branches directly to an address different from the return address or makes a system call that terminates the program.
A function that "never returns" must unconditionally do one of these five things:
for(;;);
) longjmp
, swapcontext
) pthread_exit
, _exit
, reboot
) abort
is usually some combination of 5->3, 4, and as a last resort 1, because its contract is to terminate the process after things have already gone horribly wrong: it's not out of the question that the first thing it tries (usually kill(getpid(), SIGABRT)
) won't work.
At a lower level, we could talk about what a "thread of execution" actually is, and how the operating system sets them up and tears them down, and how the OS itself is a program invoked by the bootstrap loader, and if you squint at it the right way, "running a program" is just dynamically modifying the OS's code to include the code for the program and then jumping to it... but maybe you don't want me to reel off an entire operating systems course in this answer box.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.