开发者

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

开发者 https://www.devze.com 2023-02-22 20:10 出处:网络
As wikipedia states here : \"Files that are open when a spawn call is made remain open in the child process\". (quite similar to exec())

As wikipedia states here : "Files that are open when a spawn call is made remain open in the child process". (quite similar to exec())

OK, OS has kept some files opened & ready for our newly born unaware process. Assume that our proces开发者_JS百科s reamins unaware of those previously opened files and finally decides to terminate; while programming languages like C require some internal process clean up before termination.

my question is, Does this kind of clean up affect those opened files in any way? AFAIK they're not registered anywhere or with anything inside the process itself.

The answer should somehow define the programmer's behaviour while terminating the spawn()ed process(or even an exec()ed one). Can a full clean up procedure in any way hurt the parent? (for example by removing temporary files) and hence shouldn't the programmer use _exit() instead of exit()?


Short answer: no. The C runtime does not close file handles that are open at process exit, so you can exit from the parent process or the child process without worry about messing up the other.

The kernel is responsible for closing a file handle once there are no open references to it, which happens when the kernel destroys the process. And the kernel can handle this situation just fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号