是否有必要退出之前关闭文件描述符? [英] Is there a need to close file descriptors before exit?

查看:739
本文介绍了是否有必要退出之前关闭文件描述符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当然,在大多数情况下最直接的答案就是,我坚信一个过程应该正确清理已分配的资源,但我有我的情况打开在启动文件描述符固定数量,并在退出之前关闭所有这些长期运行的系统守护进程。

Of course, the immediate answer for most situations is "yes", and I am a firm believer that a process should correctly cleanup any resources it has allocated, but what I have in my situation is a long-running system daemon that opens a fixed number of file descriptors at the startup, and closes them all before exiting.

这是一个嵌入式的平台,我试图让code尽可能紧凑,虽然没有引入任何不良作风。但由于文件描述符退出前关闭无论如何,这是否文件描述符清理code起任何作用?你总是关闭所有的文件描述符?

This is an embedded platform, and I'm trying to make the code as compact as possible, while not introducing any bad style. But since file descriptors are closed before exit anyway, does this file descriptor cleanup code serve any purpose? Do you always close all your file descriptors?

推荐答案

关闭文件描述符,当您使用它们让你的code的可重用性和易于扩展完成。这听起来好像是,你有让他们得到自动关闭的正当理由的情形。

Closing file descriptors when you are done using them makes your code more reusable and easier to extend. This sounds to me like a case where you have a valid reason for letting them get closed automatically.

这篇关于是否有必要退出之前关闭文件描述符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆