Uninterruptable process in Windows(or Linux)?

前端 未结 3 703
时光说笑
时光说笑 2020-12-05 12:12

Is there any way to make a program that cannot be interrupted (an uninterrupted program)? By that, I mean a process that can\'t be terminated by any signal, kill comma

3条回答
  •  离开以前
    2020-12-05 12:35

    On Linux, it is possible to avoid being killed by one of two ways:

    1. Become init (PID 1). init ignores all signals that it does not catch, even normally unblockable ones like SIGSTOP and SIGKILL.
    2. Trigger a kernel bug, and get your program stuck in D (uninterruptible wait) state.

    For 2., one common way to end up in D state is to attempt to access some hardware that is not responding. Particularly on older versions of Linux, the process would become stuck in kernel mode, and not respond to any signals until the kernel gave up on the hardware (which can take quite some time!). Of course, your program can't do anything else while it's stuck like this, so it's more annoying than useful, and newer versions of Linux are starting to rectify this problem by dividing D state into a killable state (where SIGKILL works) and an unkillable state (where all signals are blocked).

    Or, of course, you could simply load your code as a kernel module. Kernel modules can't be 'killed', only unloaded - and only if they allow themselves to be unloaded.

提交回复
热议问题