在没有管理员权限的情况下杀死父进程
没有管理员权限如何杀死父进程?进程A创建进程B,进程BI需要杀死进程A。
How can I kill the parent process without administrator rights? Process A creates process B, and in process B I need to kill process A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您希望 ProcessB 向 ProcessA 发出信号,表示它希望它停止运行。然后 ProcessA 可以清理所有资源并正常退出(如您的答案的评论中所建议的那样)。那么一个进程如何向另一个进程发出信号呢?这就是所谓的进程间通信 (IPC),有很多方法可以在同一台机器上或跨机器进行操作,包括消息总线、Web 服务、命名管道。
一个简单的选项是系统范围的 EventWaitHandle - 这里就是一个很好的例子 向父进程发出信号,表明子进程已完全初始化
You want to ProcessB to signal to ProcessA that it wants to it to stop running. ProcessA can then clean up any resources and exit gracefully (as suggested in the comments to your answer). So how does a Process signal something to another Process? That is called Inter-Process Communication (IPC) and there are loads of ways to do on the same machine or across machines including message buses, web-service, named pipes.
A simple option is a system-wide EventWaitHandle - good example here Signalling to a parent process that a child process is fully initialised
这样您就有了两个进程的源代码。在这种情况下,您可以使用信号量等命名系统事件来正常结束进程 A。例如, 在进程A中构造一个命名信号量,在启动进程B时将名称作为命令行参数之一传递给进程B。 从进程 B 打开现有的命名信号量 并向其发出信号以让进程 A 知道它可以结束。你也可以使用taskkill,但不优雅地结束A可能会导致A使用的资源被破坏。
so you have the source code for both processes. in this case you can use a named system event like a semaphore to gracefully end process A. for example, construct a named semaphore in process A, pass the name to process B as one of the command line parameters when starting process B. Open the existing named semaphore from process B and signal it to let process A know it can end. you could also use taskkill but not ending A gracefully could result in corrupting resources A uses.
检查此:
您可以在 C# 中启动一个进程,如下所示:
Check this:
You can start a process in C# like:
如果您知道parentProcessName,那么一切都非常简单,那么解决方案是:
如果不知道,那么就会有点困难。
All is very simple if you know parentProcessName, then solution is:
If not, then it will be a bit harder.