> 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/compat-43-1/gethostid.3.md).

# gethostid.3

`gethostid` — 获取/设置当前主机的唯一标识符

## 名称

`gethostid`, `sethostid`

## 库

Lb libc

## 概要

`#include <unistd.h>`

`Ft long Fn gethostid void Ft void Fn sethostid long hostid`

## 描述

`sethostid` 函数为当前处理器建立一个 32 位标识符，旨在所有现存 UNIX 系统中保持唯一。通常为本地机器的 DARPA Internet 地址。此调用仅允许超级用户执行，通常在引导时进行。

`gethostid` 函数返回当前处理器的 32 位标识符。

此函数已被弃用。hostid 应通过 [sysctl(3)](https://github.com/FreeBSD-Ask/freebsd-man-sc/tree/main/compat-43-1/sysctl.3.md) 设置或获取。

## 参见

[gethostname(3)](https://github.com/FreeBSD-Ask/freebsd-man-sc/tree/main/compat-43-1/gethostname.3.md), [sysctl(3)](https://github.com/FreeBSD-Ask/freebsd-man-sc/tree/main/compat-43-1/sysctl.3.md), [sysctl(8)](/man/man8/sysctl.8.md)

## 历史

`gethostid` 和 `sethostid` 系统调用出现于 4.2BSD，在 4.4BSD 中被移除。

## 缺陷

32 位标识符太小。


---

# 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/compat-43-1/gethostid.3.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.
