Why should a youngster of a vfork or fork call _ exit () as opposed to exit ()?
From the male web page of
vfork () varies from fork () because the moms and dad is put on hold till the youngster telephones to execve (2) or _ exit (2 ). The youngster shares all memory with its moms and dad, consisting of the pile, till execve () is released by the youngster. The youngster has to not return from the existing function or call exit (), yet might call _ exit ().
Why should the youngster make use of an
_exit() as opposed to merely calling
exit()? I wish this applies to both
vfork() and also
As seen earlier,
vfork does not permit the youngster procedure to access the moms and dad is memory.
exit is a C collection function (that is why it is often written as
exit(3)). It executes numerous cleaning jobs such as flushing and also closing C streams (the documents open via features proclaimed in
stdio.h) and also implementing customer - defined features signed up with
atexit. All these jobs entail analysis and also contacting the procedure memory.
_exit leaves without cleaning. It is straight a system call (which is why it is created as
_exit(2)), commonly applied by positioning the system call number in a cpu register and also implementing a certain cpu guideline (branching to the system call trainer). This does not require to access the procedure memory, so it is secure to do after
fork, there is no such constraint : the moms and dad and also youngster procedure are currently entirely independent.
You have the youngster call _ exit () to stay clear of flushing stdio (or various other) barriers when the youngster procedure leaves. Given that the youngster procedure comprises a specific duplicate of the moms and dad procedure, the youngster procedure still has whatever the moms and dad had in "stdout" or "stderr", the barriers from < stdio.h >. You can (and also will, at unfavorable times) get double results by calling exit (), one from the youngster procedure' atexit trainers, and also one from the moms and dad, when the barriers in the moms and dad procedure get complete, and also get purged.
I understand the above solution focuses on stdio.h specifics, yet that suggestion possibly rollovers to various other buffered I/O, equally as among the solutions over shows.