I’ve read that you can call either exit or _exit when you wish to terminate a process in UNIX, and also that exit frees resources (the style used when we return from main) where _exit immediately terminates without cleanup.
What is the impact of closing a program with _exit with regard to the operating environment, and why would you want to use it?
There is no difference in resources freed when exiting with
_exitversusexitunless you have installedatexithandlers. Named shared memory objects, SysV IPC resources, files in the filesystem, etc. will not be destroyed on either type of exit; memory allocated to the process (in fact, its whole virtual memory space), file descriptors, etc. will be destroyed either way. For details read the documentation in POSIX:http://pubs.opengroup.org/onlinepubs/9699919799/functions/_Exit.html
http://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html
Usually the only important difference is that stdio FILE objects might not be flushed (some writes may be lost) if you use
_exit.