Using _exit () or exit () after spawn ()?

As stated in wikipedia here : "Files opened when spawn is called remain open in the child process." (pretty similar to exec () )

OK, the OS has saved some files open and ready for our newborn uninformed process. Suppose our process does not know about previously opened files and finally decides to end; while programming languages ​​such as C require some internal cleaning process to complete.

My question is: Does this cleaning method affect these open files in any way? AFAIK they are not registered anywhere or something inside the process itself.

The answer must somehow determine the behavior of the programmer at the end of the spawn () ed process (or even exec () ed one). Can a complete cleaning procedure harm the parent in any way? (for example, by deleting temporary files) and therefore should not use the _exit () programmer exit () ?

+4
source share
1 answer

The short answer is no . The C runtime does not close the file descriptors that open when the process exits, so you can exit the parent process or child process without worrying about messing up the other.

The kernel is responsible for closing the file descriptor when there are no open links to it, which happens when the kernel destroys the process. And the kernel can handle this situation perfectly.

+3
source

Source: https://habr.com/ru/post/1347240/


All Articles