is it a good practice to close file descriptors on exit

后端 未结 6 632
南方客
南方客 2020-12-15 17:56

If for some reason, I discover a fatal situation in my program, and I would like to exit with an error code. Sometimes, the context of the fatal error is outside the scope o

6条回答
  •  孤街浪徒
    2020-12-15 18:29

    Yes. Suppose your main program is now a class in a separate program. Now you just described a resource leak. You're essentially violating encapsulation by relying on global program state, i.e. the state of the process - not your module, not a class, not an ADT, not a thread, but the whole process - being in a shutdown state.

提交回复
热议问题