How to Kill Java Process in Windows, WITHOUT killing javaw.exe? - process

I have an external Windows .exe that is actually Java application: Running the .exe starts javaw.exe, which in turn runs that Java application.
I didn't write that application and have no access to it through an API. I need to be able to kill it, however. So right now I just kill the Windows process javaw.exe, which is fine for a test machine running only that Java application but if I need finer granularity, I cannot currently do so.
My searches yielded suggestions such as Sysinternal's Process Explorer or the jps command in the JDK, but in the target systems for which I intend to provide the script, neither JDK nor Sysinternal's Process Explorer can be running.
Is there any other way that doesn't require an external tool? Does javaw.exe have a switch or command line option that lists Java processes? Is there a JRE version of jps?
Thanks.

I'd still suggest just killing the javaw.exe.
I can't see the downside, since it is the process you want to kill after all.
Remember that if you run multiple applications on the machine, they should each have a separate JVM instance. So you can still kill the specific application if you need to.

The JDK (and possibly the JRE) ship with a utility called jps which can list all Java processes but also tell you the Main-Class currently running in that JVM. If JMX/JConsole is not an option, simply parsing the output of "jps -ml" and killing the appropriate process may work.

If you want to kill an entire JVM, just kill the javaw.exe process. Within a JVM there can be multiple Java threads but there's no way to poke into a JVM and terminate a thread unless the developer of the application provided a method to do so.

Based on your comment, multiple javaw.exe programs are running and you need to know which one to kill.
You might want to try connecting to each of the processes with JConsole and inspect the JVM. There may be enough clues to determine which one to kill. Once you've identified the profile of your application, you should be able to script the logic to make it easier in the future (use JMX to get most of the information provided by JConsole).

If the executable launches javaw then exits without providing any further information it seems like you need to use your scripting language to take a snapshot of running processes on the machine before launching the executable and after the executable has finished. Then you'll be able to deduce which is the new javaw process. What scripting language are you using?

Just another approach: if you have the jdk, there is a program called jvisualVM in the bin folder. It has nice info about each running JVM context. One of the things you can see is the PID of the VM, which I use to kill the process in Windows using task manager (on windows PID is not shown by default, but you can easily enable the column by going into view -> show columns )

Related

JetBrains Rider: How to attach to elevated permissions process running locally?

I am using JetBrains Rider on Linux to debug some .NET core services. I have launched Rider without sudo permissions since my code source tree is all under my local user, but yet the installed services are running under root permissions.
Right now I'm in a predicament where in order to attach to the running processes, I have to launch a new Rider instance using sudo, but that then messes up the source code tree. Overall, this is a huge pain.
I would like to be able to attach to the elevated-permission service via an instance of Rider that is launched without sudo. I think the below is the way to do it: Run --> Attach to Remote Process, which brings up the below popup:
However, the problem with this popup is that if I click the arrow on root#localhost:22, then it shows no processes to attach to. Yet, the 4 processes are there that I would like to attach to (in the screenshot, they are 14949-14952). How can I get "no processes to attach to" to list the 4 processes in question? I have seen this done before by another developer, just think I'm missing something. Also, I'm 100% sure I know the root password.

Adding software setup to installer

I'm writing an installer for an application. Most of the installer is done and working, but I have on more step outstanding. I need some way to add a setup window to the installer, that will take user input like server address and port, etc. and write these to the relevant files for system start-up. This preferably done through a GUI of sorts inside the installer.
I've tried creating an executable file that runs after installation, but this does not always execute on different systems.
Is there a way to add a GUI to the installer itself that executes after the directory structures and files have been put into place?
Thanks in advance.
In general you should seriously consider doing this as a standalone app that runs when the app first runs and needs configuring. Then it's a program that runs in a user context and can be tested and debugged in the normal way. At least consider what the user is going to do if they want to change the server address or the port - will they need to uninstall your app and reinstall it just to change the server details or the port?
The GUI may not run correctly when started from the install for a number of reasons. It may be initiated with the system account if it's a deferred CA. It wasn't started from the interactive user shell, so it probably won't have any idea of a working directory. It's being run from an msiexec.exe process running in the system directory and maybe with a system account - that's not really the place to be doing your GUI configuration.
I assume you're using WiX, it doesn't say so in your question but it's tagged with WiX.
I would have a read of http://wix.tramontana.co.hu/tutorial/user-interface-revisited (or http://www.dizzymonkeydesign.com/blog/misc/adding-and-customizing-dlgs-in-wix-3/ has a relatively easy to read example), you can add or edit any of the dialogue boxes in the installer, you'll need to download the source to get at the built in dialog, and it does require some "play" to get everything quite right but worth it to get a professional looking installer.

How to generate EXE using JSmooth that will run JVM in the same process as the executable?

I am using JSmooth to generate EXE for my Java application. If I run the executable as administrator, the Java process runs within the same process as the executable. Otherwise it spawns a new javaw process. I would like for the java process to always run in the same process as the executable.
How can I make the executable to not spawn new process for javaw?
Not sure if you found the answer to this as I begun using JSmooth but if you look under "Skeleton" and select "Windowed Wrapper", you will see the option to "Launch java app in the exe process" checkbox. I believe this is what you're looking for.

Efficient Opensource to Debug CGI binaries in Unix

We have our code and binaries in Unix box .Few of the binaries are for web packages loaded by CGI .I use gdb in remote debugging mode to debug normal binaries but web binaries are difficult to debug because the process id changes every time the binary is loaded and gdb detaches .I heard in Visual studio there is a option to add in task manager and debug it .But i m afraid if i install Visual studio my system would go slow.Any suggestion on any other opensource tools available for efficient remote debugging of web binaries
The best thing you can do is to efactor the code so you can test most parts of it outside a CGI context with some unit testing system or something similar.
The second step would be to replay the CGI communication manually. It's not complicated - set the environment variables needed and eventuelly pipe the POST data in while running under gdb.
If that doesen't help you have to debug the web server and ask your debugger to follow child processes. Best thing is to start the httpd using the -X option so it runs with a single process itself. Then attach gdb and set the set follow-fork-mode child command. See gdb manual at http://sourceware.org/gdb/onlinedocs/gdb/Forks.html

Can you freeze a C/C++ process and continue it on a different host?

I was wondering if it is possible to generate a "core" file, copy if to another machine and then continue execution of the a core file on that machine?
I have seen the gcore utility that will make a core file from a running process. But I do not think gdb can continue execution based on a core file.
Is there any way to just dump the heap/stack and and restore those at a later point?
it's called process migration.
mosix and OpenMosix used to be able to do that. nowadays it's easiest to migrate a whole VM.
On modern systems, not from a core file, no you can't. For freezing and restoring an individual process on Linux, CryoPID and the new Kernel-based checkpoint and restart are in the works, but their abilities are currently quite limited. OpenVZ and other virtualization-like softwares can freeze and restore an entire system.
Also checkout out the Condor project. Condor can do that with parallel jobs as well. Condor also include monitors that can automatically migrate your process when some, for example, starts using their workstation again. It's really designed for utilizing spare cycles in networked environments.
This won't, in general, be sufficient to let an arbitrary process continue on another machine. In addition to the heap and stack state, there may also also open I/O handles, allocated hardware resources, etc. etc.
Your options are either to explicitly write your software in a way that lets it dump state on a signal and later resume from the dumped state, or to run your software in a virtual machine and migrate that to the alternate host - Xen and Vmware both support freeze/restore as well as live migration.
That said, CryoPID attempts to do precisely this and occasionally succeeds.
As of Feb. 2017, there's a fairly stable and mature tool, called CRIU that depends on updates to the Linux Kernel made in version 3.11 (as this was done in Sep. 2013, most modern distros should have those incorporated into their kernel versions).
It can be installed via aptitude by simply calling sudo apt-get install criu.
Instructions on how to use it.
In some cases, this can be done. For example, part of the Emacs build process is to load up all the Lisp libraries and then dump the memory image on disk for quick loading. Some other language interpreters do that too (I'm thinking of Lisp and Scheme implementations, mostly). However, they're specially designed for that kind of use, so I don't know what special things they have to do to allow that to work.
I think this would be very hard to do for a random program, but if you wrote a framework where all objects supported serialisation/deserialisation, you can then serialise all objects used by your program, and then ship that elsewhere, and deserialise them at the other end.
The other people's answers about virtualisation are on the spot, too.
Depends on the machine. It's very doable in a very small embedded system, for instance. I think it's also implemented somewhat in Beowulf clusters and other supercomputeresque apps.
There are lots of reasons you can't do what you want very easily. For example, when you restore the core file on the other machine how do you resolve file descriptors that you process had open? What about sockets, named pipes, semaphores, or any other OS-level resource? Basically unless your system is specifically designed to handle such an operation you can't naively dump a core file and move it to another machine.
I don't believe this is possible. However, you might want to look into virtualization software - e.g. Xen - which make it possible to freeze and move entire system images fromone machine to another.