Chrome 应用程序 window.onClosed 当进程从任务管理器结束时未触发 - Google Chrome
Chrome app window.onClosed not fired when process ended from Task Manager - Google Chrome
我们有一个 chrome 应用程序,我们通过再次打开主 window 来保持打开状态以响应它的 onClosed 事件。但是,当进程从 Google 的 Chrome 任务管理器结束时,不会引发此事件。为什么是这样?我们可以解决这个问题,让应用程序保持打开状态吗?到目前为止,我只在 Windows.
上 运行
Chrome任务管理器使用一个低级系统函数来终止进程,参见源代码(1, 2)。
在 Windows 上是 TerminateProcess,文档说:
A process cannot prevent itself from being terminated.
引自The Old New Thing(MS软件工程师的博客,相当有名):
Eventually you have to decide which side wins, and Windows has decided to keep users in control of their own programs and data, and keep administrators in control of their own computer. So users can kill any process they want (given sufficient privileges), they can stop any program from stealing focus, and they can delete any file they want (again, given sufficient privileges).
Programs can try to make themselves more difficult to kill (deny PROCESS_TERMINATE access, deny PROCESS_CREATE_THREAD access so people can't CreateRemoteThread(EndProcess), deny PROCESS_VM_WRITE so people can't scribble into your stack and make you doublefault, deny PROCESS_SUSPEND_RESUME so they can't suspend you), but eventually you just can't stop them from, say, elevating to Debug privilege, debugging your process, and moving EIP to "ExitProcess".
Notice that you can kill CSRSS.EXE and WINLOGON.EXE if you like. Your computer will get very angry at you, but you can do it. (Save you work first!)
Another useful question to ask yourself: "What's to prevent a virus from doing the same thing?" If there were a way to do these things, then a virus could take advantage of them and make itself invisible to Task Manager, undeletable, and unkillable. Clearly you don't want that, do you?
在 Unix 上 Chrome 任务管理器 uses kill
API function to send SIGTERM signal, which can be seen by the process, followed by unconditional SIGKILL(一段时间后):
The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
我们有一个 chrome 应用程序,我们通过再次打开主 window 来保持打开状态以响应它的 onClosed 事件。但是,当进程从 Google 的 Chrome 任务管理器结束时,不会引发此事件。为什么是这样?我们可以解决这个问题,让应用程序保持打开状态吗?到目前为止,我只在 Windows.
上 运行Chrome任务管理器使用一个低级系统函数来终止进程,参见源代码(1, 2)。
在 Windows 上是 TerminateProcess,文档说:
A process cannot prevent itself from being terminated.
引自The Old New Thing(MS软件工程师的博客,相当有名):
Eventually you have to decide which side wins, and Windows has decided to keep users in control of their own programs and data, and keep administrators in control of their own computer. So users can kill any process they want (given sufficient privileges), they can stop any program from stealing focus, and they can delete any file they want (again, given sufficient privileges).
Programs can try to make themselves more difficult to kill (deny PROCESS_TERMINATE access, deny PROCESS_CREATE_THREAD access so people can't CreateRemoteThread(EndProcess), deny PROCESS_VM_WRITE so people can't scribble into your stack and make you doublefault, deny PROCESS_SUSPEND_RESUME so they can't suspend you), but eventually you just can't stop them from, say, elevating to Debug privilege, debugging your process, and moving EIP to "ExitProcess".
Notice that you can kill CSRSS.EXE and WINLOGON.EXE if you like. Your computer will get very angry at you, but you can do it. (Save you work first!)
Another useful question to ask yourself: "What's to prevent a virus from doing the same thing?" If there were a way to do these things, then a virus could take advantage of them and make itself invisible to Task Manager, undeletable, and unkillable. Clearly you don't want that, do you?
在 Unix 上 Chrome 任务管理器 uses
kill
API function to send SIGTERM signal, which can be seen by the process, followed by unconditional SIGKILL(一段时间后):The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.