williamb1024/fs-processes

Named JobObjects

Closed this issue · 2 comments

brnbs commented

First of all great work, thanks for sharing!

Would it be possible to set a name to a JobObject?
As far as I see currently its set to null in the constructor:
_handle = Interop.Kernel32.CreateJobObject(IntPtr.Zero, null);

Is there any specific reason for this?

Relevant docs:
https://docs.microsoft.com/en-us/windows/desktop/api/WinBase/nf-winbase-createjobobjecta#parameters

When I was initially writing this code, my primary concern was the ability to monitor a process and any child processes it spawned to ensure that all processes had completed and the ability to terminate all of the processes reliably. And I wanted notifications when all of the processes exited. So I needed IOCompletionPorts associated with the JobObject.

A JobObject can only be associated with a single IOCompletionPort (at least in my testing), so opening an existing JobObject and wiring up the IOCompletionPort would wipe out any other completion port assigned to the JobObject. I didn't want to handle this issue, so I just didn't create named JobObjects or provide a "OpenJobObject" static method.

It should be possible to add support, but without removing the IOCompletionPort assignments it would probably break other code that is using the JobObject in other processes (assuming that code is also trying to use the notifications)

brnbs commented

Thank you very much for the detailed explanation!