最近,我透過 Windows 資源管理器發現我的 WSL (ZSHELL) 消耗了大量 CPU 資源(約 35%)。
然後我嘗試找出並解決這個問題,如下所示:
~ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Mar28 ? 00:00:00 /init ro
root 3 1 0 Mar28 tty1 00:00:00 /init ro
mbinary 4 3 0 Mar28 tty1 00:00:12 -zsh
mbinary 48 1 0 Mar28 tty1 00:00:00 [awk] <defunct>
mbinary 66 1 0 Mar28 tty1 00:00:00 [awk] <defunct>
mbinary 173 1 0 Mar29 tty1 00:00:00 [awk] <defunct>
mbinary 225 1 0 Mar29 tty1 00:00:00 [awk] <defunct>
mbinary 431 1 0 09:45 tty1 00:00:00 [awk] <defunct>
root 6845 1 0 09:53 tty2 00:00:00 /init ro
mbinary 6846 6845 0 09:53 tty2 00:00:04 -zsh
mbinary 7419 6846 0 10:03 tty2 00:00:00 python3
mbinary 7455 1 0 14:42 tty1 00:00:00 [awk] <defunct>
mbinary 7522 1 0 14:42 tty1 00:00:00 [awk] <defunct>
mbinary 7559 1 0 14:43 tty1 00:00:00 [awk] <defunct>
mbinary 7587 1 0 14:48 tty1 00:00:00 [awk] <defunct>
mbinary 7595 1 0 14:49 tty1 00:00:00 [awk] <defunct>
mbinary 7604 1 0 14:49 tty1 00:00:00 [awk] <defunct>
mbinary 7643 1 0 14:49 tty1 00:00:00 [awk] <defunct>
mbinary 7666 1 97 15:03 tty1 00:00:21 -zsh
mbinary 7670 7666 0 15:03 tty1 00:00:00 [awk] <defunct>
mbinary 7699 4 0 15:03 tty1 00:00:00 ps -ef
➜ ~ sudo kill -9 1
➜ ~ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Mar28 ? 00:00:00 /init ro
root 3 1 0 Mar28 tty1 00:00:00 /init ro
mbinary 4 3 0 Mar28 tty1 00:00:12 -zsh
mbinary 48 1 0 Mar28 tty1 00:00:00 [awk] <defunct>
mbinary 66 1 0 Mar28 tty1 00:00:00 [awk] <defunct>
mbinary 173 1 0 Mar29 tty1 00:00:00 [awk] <defunct>
mbinary 225 1 0 Mar29 tty1 00:00:00 [awk] <defunct>
mbinary 431 1 0 09:45 tty1 00:00:00 [awk] <defunct>
root 6845 1 0 09:53 tty2 00:00:00 /init ro
mbinary 6846 6845 0 09:53 tty2 00:00:04 -zsh
mbinary 7419 6846 0 10:03 tty2 00:00:00 python3
mbinary 7455 1 0 14:42 tty1 00:00:00 [awk] <defunct>
mbinary 7522 1 0 14:42 tty1 00:00:00 [awk] <defunct>
mbinary 7559 1 0 14:43 tty1 00:00:00 [awk] <defunct>
mbinary 7587 1 0 14:48 tty1 00:00:00 [awk] <defunct>
mbinary 7595 1 0 14:49 tty1 00:00:00 [awk] <defunct>
mbinary 7604 1 0 14:49 tty1 00:00:00 [awk] <defunct>
mbinary 7643 1 0 14:49 tty1 00:00:00 [awk] <defunct>
mbinary 7666 1 99 15:03 tty1 00:00:25 -zsh
mbinary 7670 7666 0 15:03 tty1 00:00:00 [awk] <defunct>
mbinary 7712 4 0 15:03 tty1 00:00:00 ps -ef
這不起作用。
我發現awk
使用該命令後會出現殭屍進程z
。
資訊:Windows 10:1809 WSL:Ubuntu 1804
答案1
我運行的是 Microsoft Windows 10 Pro(64 位元)版本 10.0.18362,但仍然遇到惡意 zsh 進程。此函數會殺死惡意 zsh 進程。
killzshs(){ps ax -o pid,command,ppid | grep '.*zsh.*\s1$' | awk '{print $1}' | xargs kill -9}
然後調用killzshs
該函數或將其放入點文件中。
答案2
此問題已在 Windows 版本 10.0.18362.30 中修復。細節這裡