> 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/man9/uidinfo.9.md).

# uidinfo.9

`uidinfo` — 管理 UID 信息的函数

## 名称

`uidinfo`, `uihashinit`, `uifind`, `uihold`, `uifree`

## 概要

`#include <sys/param.h>`

`#include <sys/proc.h>`

`#include <sys/resourcevar.h>`

`void uihashinit(void)`

`struct uidinfo * uifind(uid_t uid)`

`void uihold(struct uidinfo *uip)`

`void uifree(struct uidinfo *uip)`

## 描述

`uifree` 系列函数用于管理 `uidinfo` 结构。每个 `uidinfo` 结构维护每个 UID 的资源消耗计数，包括进程数和套接字缓冲区空间使用量。

`uihashinit()` 函数初始化 `uidinfo` 哈希表及其互斥锁。此函数仅在系统初始化期间调用。

`uifind()` 函数查找并返回 `uid` 对应的 `uidinfo` 结构。如果 `uid` 不存在对应的 `uidinfo` 结构，将分配并初始化一个新结构。会获取和释放 `uifree` 哈希互斥锁。

`uihold()` 函数增加 `uip` 的引用计数。会获取和释放 `uip` 的锁。

`uifree()` 函数减少 `uip` 的引用计数，如果计数达到 0 则释放 `uip`。会获取和释放 `uip` 的锁，并可能获取和释放 uidinfo 哈希互斥锁。

## 返回值

`uifind()` 返回指向已初始化 `uidinfo` 结构的指针，且不会失败。

## 作者

本手册页由 Chad David <davidc@acns.ab.ca> 编写。


---

# 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/man9/uidinfo.9.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.
