Note that there are some explanatory texts on larger screens.

plurals
  1. POKilling background process
    primarykey
    data
    text
    <p>I am running a Java program that acts as a server for my program using <code>CreateProcess</code> with no window (using the settings shown <a href="https://stackoverflow.com/questions/14729940/do-i-need-to-close-handles-to-standard-i-o-after-createprocess">here</a>). I have an object which runs the process in its constructor, saves the process handle, and uses it in the destructor in a call to <code>TerminateProcess</code> to kill it.</p> <p>My problem is that when my window is closed with the X in the corner, this destructor is never called and the process keeps running in the background, the handle is lost, and I have no indication that it is still running or a way to kill it (other the Task Manager). How can I make sure it is killed.</p> <p><strong>Larger picture</strong><br> Here is what I need to do. If you can suggest a better way altogether to accomplish this, that is fine too.<br> I need a new instance of this java server for every run of my program (sometimes even multiple times in the program). I would like to run it without any visible indication (window etc.) but this is not a requirement. I <em>do</em> need to be able to either make sure that no matter what happens the server I opened is killed when I am done with it, or a way to make sure there is no running instance of it and if so, kill it before I start a new one. (Or better yet, both.) Using the process name is no good, since it is just <code>java</code>, and I don't want to kill all Java instances on the computer. I <em>can</em> (if I knew how) check if a program is listening on the port this server uses, and if so close it.</p> <p><strong>EDIT</strong><br> I forgot to mention (if it makes a difference) that the GUI is C# and I have no control over it or over the Java program itself. I am writing a library in c++ that get called from the C# GUI and needs to use the Java server.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload