tags:

views:

85

answers:

2

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 ?

A: 

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
Tarentrulle
Mmh not what i was searching for, because i want to get the PID at launch, not afterwards, i also have many instances of this applet running
Disco
+2  A: 

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.

finnw