C get all open file descriptors

前端 未结 4 1889
南旧
南旧 2021-01-13 07:46

I want to implement behavior in my C program so that if a SIGINT happens, I close all open file descriptors. Is there a simple way to get a list of them?

4条回答
  •  粉色の甜心
    2021-01-13 08:11

    You could read out the content of /proc//fd., if available.

    But be aware of the potiential race, that might occur if your application closes some or opens new ones in between your read out /proc//fd and you are going to close what you read.

    So conculding I want to recommend Kevin Reid's approach to this.

提交回复
热议问题