在Linux上对进程执行kill -9怎么可能没有效果? [英] How is it possible that kill -9 for a process on Linux has no effect?

查看:583
本文介绍了在Linux上对进程执行kill -9怎么可能没有效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个插件,以在您访问网站时自动突出显示文本字符串.就像高亮显示的搜索结果一样,但是自动且包含许多单词;它可以用于有过敏症的人,使单词真正脱颖而出,例如,当他们浏览美食网站时.

但是我有问题.当我尝试关闭一个空的,新鲜的FF窗口时,它以某种方式阻碍了整个过程.当我终止该进程时,所有的窗口都消失了,但是Firefox进程仍然存在(父PID为1,不侦听任何信号,打开了很多资源,仍然吃着CPU,但是不会花钱).

有两个问题:

  1. 一个进程甚至怎么可能不监听kill -9(既不是用户身份也不是root用户)?

  2. 除了重新启动外,我还能做些什么吗?

这是令人反感的过程:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
digulla  16688  4.3  4.2 784476 345464 pts/14  D    Mar28  75:02 /opt/firefox-3.0/firefox-bin

ps -ef | grep firefox

相同

UID        PID  PPID  C STIME TTY          TIME CMD
digulla  16688     1  4 Mar28 pts/14   01:15:02 /opt/firefox-3.0/firefox-bin

这是剩下的唯一过程.如您所见,它不是僵尸,它正在运行!无论我是按PID还是按名称杀死它,它都不会监听kill -9!如果我尝试与strace连接,则strace也会挂起并且无法被杀死.也没有输出.我的猜测是FF挂在某个内核例程中,但是哪个?

基于sigjuice的反馈:

ps axopid,comm,wchan

可以向您显示进程挂在哪个内核例程中.就我而言,令人讨厌的插件是Beagle Indexer(openSUSE 11.1).禁用该插件后,FF再次成为一只快活的狐狸.

解决方案

如对OP的注释中所述,进程状态(STAT)为D表示该进程处于不间断睡眠"状态.用现实世界的话来说,这通常意味着它正在等待I/O,并且在I/O操作完成之前不能/不会做任何事情-包括正在死去.

处于D状态的进程通常只在操作完成之前存在一秒钟,然后返回R/S.以我的经验,如果某个进程陷在D中,那么它通常会尝试与无法访问的NFS或其他远程文件系统进行通信,尝试访问发生故障的硬盘驱动器或通过片状方式使用某些硬件设备驱动.在这种情况下,恢复并使进程终止的唯一方法是恢复并运行fs/驱动器/硬件,以便I/O可以完成,或者放弃并重新引导系统.在NFS的特定情况下,挂载最终可能还会超时并从I/O操作返回(带有失败代码),但这取决于挂载选项,将NFS挂载设置为永久等待是很常见的

这与僵尸进程不同,僵尸进程的状态为Z.

I'm writing a plugin to highlight text strings automatically as you visit a web site. It's like the highlight search results but automatic and for many words; it could be used for people with allergies to make words really stand out, for example, when they browse a food site.

But I have problem. When I try to close an empty, fresh FF window, it somehow blocks the whole process. When I kill the process, all the windows vanish, but the Firefox process stays alive (parent PID is 1, doesn't listen to any signals, has lots of resources open, still eats CPU, but won't budge).

So two questions:

  1. How is it even possible for a process not to listen to kill -9 (neither as user nor as root)?

  2. Is there anything I can do but a reboot?

[EDIT] This is the offending process:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
digulla  16688  4.3  4.2 784476 345464 pts/14  D    Mar28  75:02 /opt/firefox-3.0/firefox-bin

Same with ps -ef | grep firefox

UID        PID  PPID  C STIME TTY          TIME CMD
digulla  16688     1  4 Mar28 pts/14   01:15:02 /opt/firefox-3.0/firefox-bin

It's the only process left. As you can see, it's not a zombie, it's running! It doesn't listen to kill -9, no matter if I kill by PID or name! If I try to connect with strace, then the strace also hangs and can't be killed. There is no output, either. My guess is that FF hangs in some kernel routine but which?

[EDIT2] Based on feedback by sigjuice:

ps axopid,comm,wchan

can show you in which kernel routine a process hangs. In my case, the offending plugin was the Beagle Indexer (openSUSE 11.1). After disabling the plugin, FF was a quick and happy fox again.

解决方案

As noted in comments to the OP, a process status (STAT) of D indicates that the process is in an "uninterruptible sleep" state. In real-world terms, this generally means that it's waiting on I/O and can't/won't do anything - including dying - until that I/O operation completes.

Processes in a D state will normally only be there for a fraction of a second before the operation completes and they return to R/S. In my experience, if a process gets stuck in D, it's most often trying to communicate with an unreachable NFS or other remote filesystem, trying to access a failing hard drive, or making use of some piece of hardware by way of a flaky device driver. In such cases, the only way to recover and allow the process to die is to either get the fs/drive/hardware back up and running so the I/O can complete or to give up and reboot the system. In the specific case of NFS, the mount may also eventually time out and return from the I/O operation (with a failure code), but this is dependent on the mount options and it's very common for NFS mounts to be set to wait forever.

This is distinct from a zombie process, which will have a status of Z.

这篇关于在Linux上对进程执行kill -9怎么可能没有效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆