Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top