使用 AuthorizationExecuteWithPrivileges 启动后终止进程

发布于 2024-08-02 12:24:30 字数 99 浏览 3 评论 0原文

如果我使用 AuthorizationExecuteWithPrivileges 启动 shell 脚本,那么终止该脚本及其生成的任何其他进程的最简单方法是什么。

谢谢

If I launched a shell script using AuthorizationExecuteWithPrivileges what would be the easiest way to kill the script and any other processes that it spawned.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉风有信 2024-08-09 12:24:30

它以 root 身份运行,因此您无法从普通用户进程中终止它。你必须礼貌地要求它自行退出。

It's running as root, so you can't kill it from a regular-user process. You're going to have to ask it nicely to exit on its own.

烂人 2024-08-09 12:24:30

Apple has sample code that uses stdout to pass the PID back to the caller.

淤浪 2024-08-09 12:24:30

使用 AuthorizationExecuteWithPrivileges() 在其最后一个参数 FILE **communicationPipe 中通过引用返回的通信管道,向子进程发送一条消息,要求其将自身和其子孙出。然后,它可以使用 kill(0, SIGINT) 杀死自己及其所有后代,或者,如果需要更严厉的措施,则使用 SIGKILL

您使用的消息可以像在子进程等待文件关闭时关闭文件一样简单;到那时,它知道你已经结束了与它的对话,是时候退出了。

关于实际接收此消息的后代,有一些警告,请参阅 kill(2) 联机帮助页。只要您通过 AEWP 启动的进程没有放弃特权,这些警告基本上就无关紧要,但一个隐含的问题是,如果任何子进程将自己放入新的进程组,则这种方法将不起作用。

Use the communications pipe that AuthorizationExecuteWithPrivileges() returns by reference in its last argument, FILE **communicationPipe, to send a message to the child process that asks it to take itself and its descendants out. It can then kill itself and all its descendants using kill(0, SIGINT), or, if more drastic measures are required, SIGKILL.

The message you use can be as simple as closing the file while the child waits for the file to close; at that point, it knows you're done talking to it and it's time to take itself out.

There are some caveats about the descendants that will actually receive this message, for which see the kill(2) manpage. The caveats mostly won't matter so long as the process you started via AEWP hasn't dropped privileges, though one implicit issue is that this approach won't work if any child processes have put themselves in a new process group.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文