0

I want to replace the current Java process by a new one just like the Unix exec does. There has been already a similar question here, but I'd prefer a solution consuming as few memory as possible (the accepted answer suggest to use ClassLoaders, which could lead to memory leaks; a similar simple solution would be to use another process just to start the proper one). It can be surely done in a platform-dependent way using JNI, and I think I can do it for Unix (and a solution for Unix seem to already exist), but I know nearly nothing about the corresponding Windows API. What Windows function should I call? Has anybody done it already?

Community
  • 1
  • 1
maaartinus
  • 44,714
  • 32
  • 161
  • 320

2 Answers2

0

With Windows there are many subsystems to choose from that run on the base OS, so it helps to have some sense of what you are aiming for. For example, if you can use the C run-time library then you can just use the _exec() family of functions which are very similar to their unix cousins. Perhaps you can modify jniexec to work with windows using these.

President James K. Polk
  • 40,516
  • 21
  • 95
  • 125
  • You wrote "if you can use the C run-time library" - how should I know? What if I wanted to do it in my app on your computer (running Windows XP, Vista or 7; I don't care about older or exotic version)? AFAIK, with JNI I need to package a small DLL containing the call to `_exec`, and what more? – maaartinus Mar 27 '11 at 16:33
  • I'm not an expert on all the ways you can get the C run-time library. Certainly one way is to use Visual Studio to build your library. [Wikipedia](https://secure.wikimedia.org/wikipedia/en/wiki/Microsoft_Windows_library_files#Msvcrt.dll) has some words on this subject. – President James K. Polk Mar 27 '11 at 17:22
  • The behaviour of _exec() in Windows is rather different from that of the POSIX API. Most notably, it will not reuse the same PID, so the parent process will think that the child process has terminated. – Kohsuke Kawaguchi May 22 '11 at 23:23
0

The Win32 API doesn't include the concept of 'exec'. THe POSIX API does. The low-level WinNT API has the building blocks, but it's quite complex to use them, and, at least in the past, required recourse to undocumented functionality.

bmargulies
  • 97,814
  • 39
  • 186
  • 310