Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JobObject to optionally terminate spawned process tree #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shinfd
Copy link

@shinfd shinfd commented Jan 4, 2025

When the service is requested to stop from the management console or via sc stop command, current implementation of srvany-ng does not terminate any descendant processes spawned by the service application.

This is in line with the original srvany, as documented in the below article:

Q&A: Why doesn’t Srvany Close my Application when I Stop the Service? | | The Core Technologies Blog

Still, I thought it would be great if support for process tree termination could be added.

Using Job Objects seems to be most straightforward, so I am sending this PR as a suggestion.

The default behavior is unchanged. Please add and set UseJobObject DWORD registry parameter to 1 to enable the new behavior.

Note: As written in MS' reference, Job Objects has limitation before Win 8 and Windows Server 2012.

Windows 7, Windows Server 2008 R2, Windows XP with SP3, Windows Server 2008, Windows Vista and Windows Server 2003: A process can be associated with only one job. Jobs cannot be nested. The ability to nest jobs was added in Windows 8 and Windows Server 2012.

So using Job Object in srvany-ng may clash with program already using Job Objects, when running in older environment; hence the optional implementation.


Some things that may need to be addressed / discussed:

  • Current implementation does not clean up event handle created here on error exit
    • Followed existing pattern (1/2) for PR commit , and could not tell if these all should be changed
  • UseJobObject may not really convey what it performs and may not be appropriate for registry key
  • If PR were to be accepted, README needs to mention the new registry parameter

Can be enabled by UseJobObject=1 in registry parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant