[deepin exploration] 搜狗+fcitx5出现卡住的解决方案-2025-07-30更新shell、python版
Tofloor
poster avatar
鲜衣怒马
deepin
2025-07-14 15:16
Author

update:2025-07-30

1、最近很少遇到搜狗导致fcitx5 CPU高了,但是几天还是会遇到一次

2、更新包,之前的包shell版有问题,获取高CPU有问题

3、python版不能自动启动fcitx5 服务~

4、本次只更新shell版

fcitx5-monitor-deb-all-root-dp23_1.0.35.zip

update:2025-07-28

解决了部分版本在卡住时不能恢复的问题:

删除了不可用的包

搜狗+Fcitx5 高 CPU 监控解决方案

可解决近期出现的搜狗输入法莫名其妙的导致卡键盘卡输入法的问题。

📌 方案总览

方案 自动化 安装难度 适用场景
🔧 基础方案 ❌ 手动 ⭐ 极简 临时应急
🚀 高级方案 ✅ 全自动 ⭐⭐⭐ 中等 长期监控(技术用户)
📦 DEB包 ✅ 全自动 ⭐ 极简 一键安装(普通用户)

🔧 方案一:基础方案(手动执行)

✅ 优点

  • 无需配置,即开即用
  • 轻量级(仅1行命令)

❌ 缺点

  • 需手动执行,无法自动处理

📜 脚本内容

#!/bin/bash
kill -9 $(ps -ef | grep "/usr/bin/fcitx5 -r" | grep -v grep | awk '{print $2}')

deepin V23使用下面的命令

#!/bin/bash
kill -9 $(ps -ef | grep "/usr/bin/fcitx5" | grep -v grep | awk '{print $2}')

💻 使用步骤

  1. 保存为 kill_fcitx5.sh
  2. 添加执行权限:
    chmod +x kill_fcitx5.sh
    
  3. 卡顿时运行:
    ./kill_fcitx5.sh
    

🚀 方案二:高级方案(自动监控)-2025-07-19更新

✅ 优点

  • 1秒检测间隔
  • 使用top -bn1 方式获取CPU 更准确,CPU>50%自动杀死进程
  • 资源限制(内存50M/CPU20%)

❌ 缺点

  • 需要编辑配置文件
  • 卸载需手动清理

🛠️ 实施步骤

1. 创建监控脚本

sudo nano /usr/local/bin/fcitx5-monitor.sh

2. 设置权限

#!/bin/bash

version="1.0.10"
THRESHOLD=50
INTERVAL=2
SUCC_SLEEP=300
LOG_FILE="/var/log/fcitx5-monitor.log"

touch "$LOG_FILE" || { echo "无法写入日志文件: $LOG_FILE"; exit 1; }

log() {
    echo "[$(date '+%F %T')] $1" >> "$LOG_FILE"
}

while true; do
    top_output=$(top -bn1 | awk 'NR==7 || /fcitx5$/')
    CPU_NF=$(echo "$top_output" | awk 'NR==1 {for (i=1; i<=NF; i++) if ($i ~ /%CPU/) print i}')
    echo "$top_output" | awk '/fcitx5$/' | awk -v nf="$CPU_NF" -v th="$THRESHOLD" '{cpu=int($nf); if (cpu >= th) print $1, cpu}' | \
    while read -r PID CPU_USAGE; do
        [[ -z "$PID" ]] && break
        log "检测到高CPU: PID=$PID, CPU=${CPU_USAGE}% > ${THRESHOLD}%,正在杀死..."
        if kill -9 "$PID" 2>/dev/null; then
            log "成功杀死fcitx5 (PID=$PID)"
            sleep "$SUCC_SLEEP"
        else
            log "杀死进程失败 (PID=$PID)"
        fi
    done
    sleep "$INTERVAL"
done
sudo chmod +x /usr/local/bin/fcitx5-monitor.sh
sudo chown root:root /usr/local/bin/fcitx5-monitor.sh

3. 创建Systemd服务

sudo nano /etc/systemd/system/fcitx5-monitor.service
[Unit]
Description=Fcitx5 High CPU Monitor
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/fcitx5-monitor.sh
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=fcitx5-monitor
MemoryMax=50M
CPUQuota=20%

[Install]
WantedBy=multi-user.target

4. 启动服务

sudo systemctl daemon-reload
sudo systemctl enable --now fcitx5-monitor.service

5. 验证状态

systemctl status fcitx5-monitor.service
journalctl -u fcitx5-monitor -f  # 实时日志

📦 方案三:一键安装(DEB包)-2025-07-19更新

✅ 优点

  • 双击安装
  • 自动配置服务
  • 无需命令行

❌ 缺点

  • 卸载需手动操作

📂 DEB包结构



fcitx5-monitor-deb/
├── usr/
│   └── local/
│       └── bin/
│           └── fcitx5-monitor.sh
├── etc/
│   └── systemd/
│       └── system/
│           └── fcitx5-monitor.service
└── DEBIAN/
    ├── control
    └── postinst
    ├── prerm         # 卸载前执行

🎯 最终建议

用户类型 推荐方案
普通用户 📦 DEB包一键安装
技术用户 🚀 高级方案
临时解决 🔧 基础方案

🎯 版本历史

版本 日期 更新内容
1.0.13 2025-07-25 因为最近改用V23了,适配下脚本,V23不会自动拉起fcitx5,所以杀掉进程后要自己拉
1.0.10 2025-07-19 尽量减少CPU和内存资源消耗,减少变量赋值,降低执行频率
1.0.9 2025-07-19 更改监控命令为 "top -bn1",ps 方式获取的CPU不准确,top 方式更准确
1.0.3 2025-07-15 新增卸载时清理,kill成功后等待5分钟,等待下一个进程自动拉起后稳定后,再开始监测
1.0.0 2025-07-10 初始发布,实现基础监控功能

立即体验无卡顿的输入法环境! 🚀

问题1:已修复
20250715-20:49 更新,如果有之前安装了的请更新版本,太灵敏了,会在fcitx5起来的瞬间又吧进程杀死了,

image.png

问题2:ps -eo 方式获取的CPU不准确,卡顿时有时 大于1%,有时小于1%;改用top -bn1 方式获取CPU,自动适配CPU列

同时更新了方案2和方案3,请知!!!!
下面的1.0.10版本是可以正常的版本,在不影响体验的情况下优化了资源占用,

本来占用也不多,但是1s 1次和2s 1次,基本不影响体验,但是资源少一些

fcitx5-monitor-deb-all-root-v1.0.10.zip

  1. 双击安装(或命令行):
    sudo dpkg -i fcitx5-monitor.deb
    
  2. 验证安装:
    systemctl status fcitx5-monitor.service
    

效果图
(安装后服务状态示例)

常见问题

1. 如何调整CPU阈值?

sudo nano /usr/local/bin/fcitx5-monitor.sh
# 修改THRESHOLD值(默认5)
THRESHOLD=10

2. 如何卸载服务?

sudo dpkg -r fcitx5-monitor #会清除包括脚本、service文件、日志文件在内的所有应用数据

3. 如何查看日志?

journalctl -u fcitx5-monitor -n 50  # 最近50条
Reply Favorite View the author
All Replies
2 / 2
To page
jinzong324
deepin
2025-07-18 18:53
#21

码,最近卡了好多次,都是重启系统,下次试下kissing_heart

Reply View the author
鲜衣怒马
deepin
2025-07-19 09:57
#22
jinzong324

码,最近卡了好多次,都是重启系统,下次试下kissing_heart

我最近基本几天才遇到一次了,很久没触发kill 进程了

Reply View the author
鲜衣怒马
deepin
2025-07-21 14:18
#23

使用VSC + 搜狗时容易出现fictx5卡,1.0.10 版本下,几乎无感,不看日志都感受不到卡就恢复了
image.png

Reply View the author
2 / 2
To page