> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man1/fuser.1.md).

# fuser.1

`fuser` — 列出打开了一个或多个文件的所有进程的 ID

## 名称

`fuser`

## 概要

`fuser [-cfkmu] [-M core] [-N system] [-s signal] file`

## 描述

`fuser` 实用程序将打开一个或多个命名文件的进程的 PID 写入标准输出。对于块特殊设备和字符特殊设备，所有使用该设备上文件的进程都会被列出。如果某文件被进程显式打开，或者是该进程的工作目录、根目录、Jail 根目录、活动可执行文本、内核 trace 文件或控制终端，则认为该文件被该进程打开。如果指定了 `-m` 选项，`fuser` 实用程序还会查找 mmapped 文件。

可用选项如下：

**`-c`** 将文件视为挂载点，报告文件系统中所有打开的文件。

**`-f`** 报告必须仅针对命名文件。

**`-k`** 向报告的进程发送信号（默认为 `SIGKILL`）。

**`-M`** `core` 从指定的 core 文件而非默认的 **`/dev/kmem`** 中提取与名字列表关联的值。

**`-m`** 同时查找 mmapped 文件。

**`-N`** `system` 从指定的 system 文件而非默认值中提取名字列表，默认值为系统启动时所使用的内核映像。

**`-s`** `signal` 使用给定的信号名而非默认的 `SIGKILL`。

**`-u`** 将每个进程关联的用户名写入标准错误输出。

以下符号会写入标准错误输出，用于指示文件的使用方式：

**a** 文件以仅追加方式打开（指定了 `O_APPEND`）。

**c** 文件是进程的当前工作目录。

**d** 进程向此文件写入时绕过文件系统缓存（指定了 `O_DIRECT`）。

**e** 持有独占锁。

**j** 文件是进程的 Jail 根目录。

**m** 文件被 mmap 映射。

**r** 文件是进程的根目录。

**s** 持有共享锁。

**t** 文件是进程的内核 trace 文件。

**w** 文件以写入方式打开。

**x** 文件是进程的可执行文本。

**y** 进程将此文件用作其控制终端。

## 退出状态

`fuser` 实用程序成功时退出值为 0，发生错误时大于 0。

## 实例

命令 `fuser -fu .` 将正在使用当前目录的进程的进程 ID 写入标准输出，并将这些进程使用该目录的方式以及与这些进程关联的用户名写入标准错误输出。

## 参见

fstat(1), [ps(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/ps.1.md), [systat(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/systat.1.md), [iostat(8)](/man/man8/iostat.8.md), pstat(8), [vmstat(8)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man8/vmstat.8.md)

## 标准

`fuser` 实用程序预期符合 IEEE Std 1003.1-2004 ("POSIX.1")。

## 历史

`fuser` 实用程序出现于 FreeBSD 9.0。

## 作者

`fuser` 实用程序及本手册页由 Stanislav Sedov <stas@FreeBSD.org> 编写。

## 缺陷

由于 `fuser` 获取的是系统快照，其结果仅在很短的一段时间内是正确的。当通过 kvm(3) 接口工作时，报告将局限于 `fuser` 实用程序所了解的文件系统（目前仅有 cd9660、devfs、nfs、ntfs、nwfs、udf、ufs 和 zfs）。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man1/fuser.1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
