C get all open file descriptors

前端 未结 4 1895
南旧
南旧 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条回答
  •  萌比男神i
    2021-01-13 08:17

    I'd use brute force: for (i = 0; i < fd_max; ++i) close (i);. Quick and pretty portable.

提交回复
热议问题