> 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/man4/sem.4.md).

# sem.4

`sem` — POSIX 信号量

## 名称

`sem`

## 概要

`要将此驱动编译进内核，请将以下行添加到你的内核配置文件中：`

> options P1003\_1B\_SEMAPHORES

`或者，要在引导时以模块形式加载此驱动，请将以下行添加到 loader.conf(5) 中：`

```sh
sem_load="YES"
```

`要在运行时以模块形式加载此驱动，请以 root 身份执行以下命令：`

> kldload sem

## 描述

`sem` 工具提供标准 C 库（`libc`）使用的系统调用，以实现 POSIX 信号量。此工具为 `sem_init` 和 `sem_wait` 等函数提供支持。它既可以作为内核选项静态包含，也可以作为动态内核模块使用。

## 参见

sem\_destroy(3), sem\_getvalue(3), sem\_init(3), sem\_open(3), sem\_post(3), sem\_wait(3), [config(8)](/man/man8/config.8.md), [kldload(8)](/man/man8/kldload.8.md), [kldunload(8)](/man/man8/kldunload.8.md)

## 历史

`sem` 工具最早出现于 FreeBSD 5.0。


---

# 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/man4/sem.4.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.
