Check the open FD limit for a given process in Linux

后端 未结 7 1859
粉色の甜心
粉色の甜心 2020-12-04 10:13

I recently had a Linux process which “leaked” file descriptors: It opened them and didn\'t properly close some of them.

If I had monitored this, I could tell – in adv

7条回答
  •  孤城傲影
    2020-12-04 11:02

    You asked for bash/python methods. ulimit would be the best bash approach (short of munging through /proc/$pid/fd and the like by hand). For python, you could use the resource module.

    import resource
    
    print(resource.getrlimit(resource.RLIMIT_NOFILE))
    
    $ python test.py
    
    (1024, 65536)
    

    resource.getrlimit corresponds to the getrlimit call in a C program. The results represent the current and maximum values for the requested resource. In the above example, the current (soft) limit is 1024. The values are typical defaults on Linux systems these days.

提交回复
热议问题