Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

processes in LInux

everyone I have some question regarding programs: if I have for example some program:

int main()
{
int value = 0;
...
return value;
}

my OS creates new process, which uses execv() to run this program, when I do return value I transfer value back to the process, my question how will this process end? does it execute exit(value), when value is the value from my program? thanks in advance for any help

like image 351
likeIT Avatar asked Aug 12 '26 09:08

likeIT


1 Answers

Returning from main() is basically equivalent to calling exit(), and starts the Normal Termination procedure.

Normal termination causes the following actions:

  1. Functions that were registered with the atexit or on_exit functions are called in the reverse order of their registration. This mechanism allows your application to specify its own “cleanup” actions to be performed at program termination. Typically, this is used to do things like saving program state information in a file, or unlocking locks in shared data bases.

  2. All open streams are closed, writing out any buffered output data. In addition, temporary files opened with the tmpfile function are removed.

  3. _exit() is called, terminating the program.

Finally, the system does the usual cleanup after the process termination (files closed, exit code reported, child processed terminated or reassigned to init...) See Termination internals

like image 57
grep Avatar answered Aug 15 '26 01:08

grep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!