# Nofile

1、`/etc/systemd/system.conf`

该文件会影响以systemd管理的进程（即xxx.service），比如docker服务如果是用systemd管理，那么dockerd进程的打开文件数会受到该文件的影响。 同时我们也可以在xxx.service中修改，以覆盖`/etc/systemd/system.conf`的值

2、/etc/systemd/system.d/

该目录下的文件的值会覆盖`/etc/systemd/system.conf`中的值

3、/etc/security/limits.conf

该文件会影响某个用户下的进程，可以简单理解为该用户下的单个进程的打开文件数上限

3、/etc/security/limits.d/

该目录下的文件中的配置会覆盖`/etc/security/limits.conf`的值

4、容器

容器中的进程是以root用户运行的，但是容器中的进程的打开文件数上限，是由docker的启动参数控制的，该参数的默认值为65536， 所以容器中的进程的打开文件数与上述的配置没有关系。

比如，我们可以通过以下的方式来修改容器中进程的`Soft NoFile`与`Hard NoFile`都为`1048576`

```
$ dockerd --default-ulimit nofile=1048576:1048576
```

5、上面可配置的地方这么多，如何查看某个进程真正的打开文件数上限？

```
$ cat /proc/<pid>/limits
```

6、如果查看一个进程当前打开了多少个文件？

```
$ ls -l /proc/<pid>/fd | wc -l
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pshizhsysu.gitbook.io/linux/nofile.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
