Get PID of javaws jnlp applet under linux

风流意气都作罢 提交于 2020-01-05 02:59:19

问题


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

Using this command :

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

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.

Any clues ?

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 "$@"

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


回答1:


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.


Example:

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

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

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




回答2:


I don't know if this would do the trick, but to find a pid, more generally, I use this alias

alias prs='ps faux|grep -v grep|grep "$@"'

and then

prs my_prog


来源:https://stackoverflow.com/questions/3492850/get-pid-of-javaws-jnlp-applet-under-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!