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

update:2025-09-01

开学季更新一波:

为什么要更新呢?

1、因为官方升级之后,原来的方法会导致误杀,所以需要增加检测次数以避免误杀~,控制权限也有必要,所以更新了一次

2、V23 需要支持脚本启动fcitx5,root权限启动有问题,所以改为对应用户运行,可以启动fcitx5 并正常运行,主要是不想手动介入,脚本全处理好了,V25 fcitx5会自己拉起,所以原来V25使用时,可以用root运行服务和脚本

服务改为当前用户运行

增加检测次数,现在已经没有那么频繁出现,但是cpu高频繁出现后恢复,所以增加检测次数,10次检测都出现cpu高才杀死进程等待自动重启或脚本重启

高CPU范围修改为90%,避免误杀

fcitx5-monitor-deb-all-user-dp23_1.0.71.zip

注意:此版本安装后需手动执行:因为是当前用户的服务,不能在安装时自启动,所有需要执行一次

dp25@dp25-PC:~$ systemctl --user status fcitx5-monitor.service
● fcitx5-monitor.service - Fcitx5 High CPU Monitor
     Loaded: loaded (/etc/xdg/systemd/user/fcitx5-monitor.service; enabled; preset: enabled)
     Active: active (running) since Fri 2025-08-29 16:13:14 CST; 2 days ago
   Main PID: 1253517 (fcitx5-monitor.)
      Tasks: 4 (limit: 18686)
     Memory: 5.5M (max: 50.0M available: 44.4M peak: 7.0M)
        CPU: 5min 53.324s
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/fcitx5-monitor.service
             ├─1253517 /bin/bash /home/dp25/.local/bin/fcitx5-monitor.sh
             ├─1402320 /bin/bash /home/dp25/.local/bin/fcitx5-monitor.sh
             ├─1402321 top -bn1
             └─1402322 grep -E "(PID|%CPU|fcitx5\$)"
dp25@dp25-PC:~$ cat /home/dp25/.local/share/fcitx5-monitor.log 
[2025-08-29 16:13:14] fcitx5-monitor 停止运行
[2025-08-29 16:13:14] fcitx5-monitor v1.0.71 启动
[2025-08-29 16:29:15] 检测到fcitx5高CPU: PID=616539, CPU=92% (第1次检测)
[2025-08-29 16:29:18] fcitx5 CPU使用率恢复正常: PID=616539, CPU=0%
[2025-08-29 16:36:20] 检测到fcitx5高CPU: PID=616539, CPU=93% (第1次检测)
systemctl --user daemon-reload
systemctl --user enable fcitx5-monitor.service
systemctl --user start fcitx5-monitor.service
systemctl --user restart fcitx5-monitor.service
systemctl --user status fcitx5-monitor.service

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
CTZ老斑鸠
deepin
2025-08-30 17:10
#24

感觉是搜狗和vsc在打架,在vsc里用搜狗打字就会有概率卡死,我在debian13和ubuntu24.04上也偶发过同样的问题,卸了搜狗换万象之后再没出现过doubt

Reply View the author
鲜衣怒马
deepin
2025-08-30 20:44
#25
CTZ老斑鸠

感觉是搜狗和vsc在打架,在vsc里用搜狗打字就会有概率卡死,我在debian13和ubuntu24.04上也偶发过同样的问题,卸了搜狗换万象之后再没出现过doubt

我也是用vsc经常出现,为了顺畅写了这个服务处理

Reply View the author
徐庆
deepin
2025-09-04 07:05
#26
姬志远(白菜男)

用自带五笔。

自带五笔能不能有快速输入日期时间和圆圈数字序号的方法?

自带的在一些场景下面直接不能用,比如在飞书的会话里面打不出字来

Reply View the author
鲜衣怒马
deepin
2025-09-04 08:20
#27
徐庆

自带的在一些场景下面直接不能用,比如在飞书的会话里面打不出字来

可以用万象输入法,不想用搜狗的话,用搜狗可以用这个服务保持不卡死可用

Reply View the author
2 / 2
To page