c
BIN
docs/notes/01_c-basic/01_xdx/assets/175.gif
Normal file
After Width: | Height: | Size: 104 KiB |
BIN
docs/notes/01_c-basic/01_xdx/assets/176.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
docs/notes/01_c-basic/01_xdx/assets/177.gif
Normal file
After Width: | Height: | Size: 99 KiB |
BIN
docs/notes/01_c-basic/01_xdx/assets/178.gif
Normal file
After Width: | Height: | Size: 59 KiB |
BIN
docs/notes/01_c-basic/01_xdx/assets/179.png
Normal file
After Width: | Height: | Size: 16 KiB |
@ -1854,3 +1854,60 @@ cp perf /usr/bin/
|
||||
|
||||

|
||||
|
||||
## 8.7 WSL 启用 systemd
|
||||
|
||||
### 8.7.1 概述
|
||||
|
||||
* 根据 [systemd.io](https://systemd.io/):“systemd 是 Linux 系统的基本构建基块套件。 它提供一个系统和服务管理器,该管理器作为 PID 1 运行并启动系统的其余部分。”
|
||||
* Systemd 主要是一个 init 系统和服务管理器,它包括按需启动守护程序、装载和自动装载点维护、快照支持以及使用 Linux 控制组进行跟踪等功能。
|
||||
* 大多数主要的 Linux 发行版现在都运行 systemd,因此在 WSL 上启用它可使体验更接近于使用裸机 Linux。
|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> 默认情况下,在 WSL2 中,只有 Ubuntu 才会将 systemd 作为 pid-1 的守护进程启动整个 WSL2,而其余的 Linux 的守护进程并不是这样的。
|
||||
|
||||
* 检查进程树,判断 systemd 是否正在运行:
|
||||
|
||||
```shell
|
||||
ps -p 1 -o comm= # 如果显示 systemd ,则表示 systemd 正在运行
|
||||
```
|
||||
|
||||

|
||||
|
||||
### 8.7.2 操作步骤
|
||||
|
||||
* ① 查询 WSL2 的版本,确保 WSL2 的版本为 `0.67.6` 或更高版本:
|
||||
|
||||
```shell
|
||||
# 如果未满足要求,则使用 wsl --update 更新 WSL2 版本
|
||||
wsl --version # 在 win 中的 cmd 或 PowerShell
|
||||
```
|
||||
|
||||

|
||||
|
||||
* ② 向 `/etc/wsl.conf` 配置文件中写入以下内容:
|
||||
|
||||
```shell
|
||||
cat <<EOF | tee /etc/wsl.conf
|
||||
[boot]
|
||||
systemd=true
|
||||
EOF
|
||||
```
|
||||
|
||||

|
||||
|
||||
* ③ 重启 WSL 实例:
|
||||
|
||||
```shell
|
||||
wsl --shutdown # 在 win 中的 cmd 或 PowerShell
|
||||
```
|
||||
|
||||

|
||||
|
||||
* ④ 查看是否启用成功:
|
||||
|
||||
```shell
|
||||
ps -p 1 -o comm=
|
||||
```
|
||||
|
||||

|
||||
|
BIN
docs/notes/01_c-basic/03_xdx/assets/45.gif
Normal file
After Width: | Height: | Size: 114 KiB |
BIN
docs/notes/01_c-basic/03_xdx/assets/46.gif
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
docs/notes/01_c-basic/03_xdx/assets/47.gif
Normal file
After Width: | Height: | Size: 168 KiB |
BIN
docs/notes/01_c-basic/03_xdx/assets/48.gif
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
docs/notes/01_c-basic/03_xdx/assets/49.gif
Normal file
After Width: | Height: | Size: 126 KiB |
BIN
docs/notes/01_c-basic/03_xdx/assets/50.gif
Normal file
After Width: | Height: | Size: 477 KiB |
BIN
docs/notes/01_c-basic/03_xdx/assets/51.gif
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
docs/notes/01_c-basic/03_xdx/assets/52.gif
Normal file
After Width: | Height: | Size: 40 KiB |
@ -2352,3 +2352,83 @@ man ascii
|
||||
|
||||

|
||||
|
||||
## 3.2 WSL2 中设置默认编码为中文
|
||||
|
||||
### 3.2.1 概述
|
||||
|
||||
* 查看 WSL2 的 Linux 发行版的默认编码:
|
||||
|
||||
```shell
|
||||
echo $LANG
|
||||
```
|
||||
|
||||

|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> `C.UTF-8` 是一种字符编码设置,结合了 `C` 区域设定和 `UTF-8` 字符编码。
|
||||
>
|
||||
> * ① **C 区域设定**:这是一个标准的、最小化的区域设置,通常用于系统默认的语言环境。`C` 区域设定下,所有字符都被认为是 ASCII 字符集的一部分,这意味着仅支持基本的英文字符和符号。在 `C` 区域设定中,字符串的排序和比较是基于简单的二进制值比较,这与本地化的语言设置相比相对简单。
|
||||
> * ② **UTF-8 编码**:UTF-8 是一种变长的字符编码方式,可以编码所有的 Unicode 字符。它是一种广泛使用的字符编码,能够支持多种语言和符号。每个 UTF-8 字符可以由1到4个字节表示,这使得它兼容 ASCII(对于标准 ASCII 字符,UTF-8 只使用一个字节)。
|
||||
>
|
||||
> 因此,`C.UTF-8` 结合了 `C` 区域设定和 UTF-8 字符编码的优势。使用 `C.UTF-8` 时,系统默认语言环境保持简单和高效,同时支持更广泛的字符集,特别是多语言和非英语字符。这样可以在需要兼容性的同时,提供对全球化字符的支持。
|
||||
|
||||
### 3.2.2 AlmaLinux9 设置默认编码
|
||||
|
||||
* ① 搜索中文语言包:
|
||||
|
||||
```shell
|
||||
dnf search locale zh
|
||||
```
|
||||
|
||||

|
||||
|
||||
* ② 安装中文语言包:
|
||||
|
||||
```shell
|
||||
dnf -y install glibc-langpack-zh
|
||||
```
|
||||
|
||||

|
||||
|
||||
* ③ 切换语言环境为中文:
|
||||
|
||||
```shell
|
||||
localectl set-locale LANG=zh_CN.UTF-8
|
||||
```
|
||||
|
||||

|
||||
|
||||
* ④ 手动加载配置文件,使其生效:
|
||||
|
||||
```shell
|
||||
source /etc/locale.conf
|
||||
```
|
||||
|
||||

|
||||
|
||||
### 3.2.3 Ubuntu 22.04 设置默认编码
|
||||
|
||||
* ① 安装中文语言包:
|
||||
|
||||
```shell
|
||||
sudo apt update -y && apt install language-pack-zh-hans -y
|
||||
```
|
||||
|
||||

|
||||
|
||||
* ② 切换环境为中文:
|
||||
|
||||
```shell
|
||||
update-locale LANG=zh_CN.UTF-8 LANGUAGE=zh_CN:zh
|
||||
```
|
||||
|
||||

|
||||
|
||||
* ③ 手动加载配置文件,使其生效:
|
||||
|
||||
```shell
|
||||
source /etc/default/locale
|
||||
```
|
||||
|
||||

|
||||
|