Disco
Disco

Reputation: 4386

Get PID of javaws jnlp applet under linux

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 ?

Upvotes: 2

Views: 1758

Answers (2)

finnw
finnw

Reputation: 48629

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.

Upvotes: 2

IcanDivideBy0
IcanDivideBy0

Reputation: 1675

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

Upvotes: 1

Related Questions