在Linux下获取javaws jnlp applet的PID [英] Get PID of javaws jnlp applet under linux

查看:84
本文介绍了在Linux下获取javaws jnlp applet的PID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从bash运行一个Java(jnlp)小程序,并获取所创建进程的PID.

I'm trying to run a java (jnlp) applet from bash and get the PID of the created process.

使用此命令:

javaws myapplet.jnlp > /dev/null & echo $!

这将返回加载jnlp的java的第一个实例的pid;我想,但与最终的Java进程运行无关.

This returns a pid of the first instance of java that loads the jnlp; i guess, but has nothing to do with the final java process running.

有任何线索吗?

找出原始的javaws如下:

Found out the original javaws as follows :

#!/bin/sh
prog="$0"
while [ -h "$prog" ]; do prog=$(readlink -f $prog); done
[ $# -eq 0 ] && set -- -viewer
exec $(dirname $prog)/javaws.real "$@"

有没有一种修改方法,可以给出子进程的PID?

Is there a way to modify so it gives the PID of the child process ?

推荐答案

创建 agent .jar文件,然后使用javaws的-J选项加载该文件. -J参数直接传递到目标VM,并与.jnlp文件中的vm args组合在一起,因此您可以在与应用程序相同的过程中加载本地代理程序库.

Create an agent .jar file and load that using the -J option of javaws. -J arguments are passed directly to the target VM and are combined with the vm args in the .jnlp file, so you can load a local agent library in the same process as the application.

示例:

此代理库包含用于存储当前PID的premain方法(通过 JNA )在文本文件中访问.

This agent library contains a premain method that stores the current PID (accessed via JNA) in a text file.

假设getpid.jarjna.jar在当前目录中,则可以使用以下命令启动它:

Assuming getpid.jar and jna.jar are in the current directory it can be launched with:

javaws -J-javaagent:getpid.jar=pid.txt myapplet.jnlp

这会将小程序的PID写入文件pid.txt之后启动小程序.

This will start the applet after writing its PID to the file pid.txt.

这篇关于在Linux下获取javaws jnlp applet的PID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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