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 Job objects in lieu of a shutdown hook on Windows. #133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ This property controls how long the processing thread(s) remains after the last
order to avoid the overhead of starting up another processing thread, if processes are frequently run it may be desirable
for the processing thread to remain (linger) for some amount of time (default 2500ms).

##### ``com.zaxxer.nuprocess.enableShutdownHook``
On Windows, this enables creating processes with job objects, which ensures they die when the parent process dies, in all
circumstances. On Linux and macOS, this creates a Java shutdown hook that quits created, running processes. This has the
same limitations as shutdown hooks, which may not run in certain circumstances like termination. The default value is "true".

#### Related Projects
Charles Duffy has developed a Clojure wrapper library [here](https://github.com/threatgrid/asynp).
Julien Viet has developed a Vert.x 3 library [here](https://github.com/vietj/vertx-childprocess).
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/zaxxer/nuprocess/windows/NuKernel32.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public static native int ReadFile(HANDLE hFile, ByteBuffer lpBuffer, int nNumber
public static native int WriteFile(HANDLE hFile, ByteBuffer lpBuffer, int nNumberOfBytesToWrite, IntByReference lpNumberOfBytesWritten,
NuKernel32.OVERLAPPED lpOverlapped);

public static native HANDLE CreateJobObject(SECURITY_ATTRIBUTES attrs, String name);

public static native boolean SetInformationJobObject(HANDLE hJob, int JobObjectInfoClass, Pointer lpJobObjectInfo, int cbJobObjectInfoLength); // {return false;};

public static native boolean AssignProcessToJobObject(HANDLE hJob, HANDLE hProcess); // {return false;};

public static native boolean TerminateJobObject(HANDLE hJob, long uExitCode); // {return false;};

/**
* The OVERLAPPED structure contains information used in
* asynchronous (or overlapped) input and output (I/O).
Expand Down
Loading