• 查看系统用户所有限制值:
    ulimit -a
  1. 首先尝试 ulimit -n 4096 , 确认能正确更改进程的max fd 数目。
  2. 后来发现可以很方便的在init.rc/init.xxxx.rc 里面进行设定, 通常设定分成两种,
    • 一种是for all user process, 这种就是针对bootup 时对init process 进行设定(已验证). 比如
      on init
          ......
          # Allow up to 32K FDs per process
          #setrlimit nofile 32768 32768  #can't work at N, work at P
          setrlimit 7  4096  4096  # can  work ta N
    • 另外一种就是针对某个process 来进行设定, 这个通常是针对某个 service 进行设定:
      service camerahalserver /vendor/bin/hw/camerahalserver
          class main
          user cameraserver
          group audio camera input drmrpc sdcard_rw system media graphics
          ioprio rt 4
          capabilities SYS_NICE
          writepid /dev/cpuset/camera-daemon/tasks /dev/stune/top-app/tasks
          #limit VSS to 4GB
          rlimit as 0x100000000 0x100000000
          #limit malloc to 1GB
          rlimit data 0x40000000 0x40000000

参考

https://blog.csdn.net/cigogo/article/details/86023067