如何使用JNA/JNI替换Windows中的当前Java进程? [英] How to replace the current Java process in Windows using JNA/JNI?

查看:82
本文介绍了如何使用JNA/JNI替换Windows中的当前Java进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个新的程序替换当前的Java程序,就像 Unix exec .已经有一个类似问题,但是我更喜欢一个尽可能少消耗内存的解决方案(解决方案(对于Unix似乎已经存在),但是我对相应的Windows API几乎一无所知.我应该调用什么Windows函数?有人做过吗?

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?

推荐答案

在Windows上,有许多子系统可以从运行在基本OS上的子系统中进行选择,因此有助于您了解目标.例如,如果可以使用C运行时库,则可以只使用 _exec() 函数家族,与它们的unix表亲非常相似.也许您可以修改jniexec以使其与Windows一起使用.

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.

这篇关于如何使用JNA/JNI替换Windows中的当前Java进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆