1

I am running two java application in ubuntu,I googled for this,but i am not getting how to give the unique process name to each java application.I am running the applications as a jar files (java -jar app.jar).But when i see the process using shell command top .

It is showing only java,not applications name.Any help regarding this.

ruhil
  • 11
  • 3

3 Answers3

0

You can try ps -aef | grep java from your terminal. It will list running Java commands, from which you can deduce application names by looking at the command parameters.

Bastien Jansen
  • 8,756
  • 2
  • 35
  • 53
  • I want to bring the java application to front of the user by using process name like (wmctrl -a "Mozilla Firefox"),but for java application wmctrl is not working.Can we get the java application to front by using process id instead of process name – ruhil Apr 05 '13 at 13:58
0

If this is to start / stop a Java process, you can do a startup script like that :

#!/bin/sh

PROGRAM_NAME=sicm
PROGRAM_HOME=/usr/local/sicm
PIDFILE=/var/run/$PROGRAM_NAME.pid

application_start() {
        CMDLINE="/usr/lib/java/bin/java -jar $PROGRAM_NAME.jar"
        echo -n "Starting $PROGRAM_NAME daemon: $CMDLINE"
        cd $PROGRAM_HOME

        /usr/lib/java/bin/java -classpath lib -jar $PROGRAM_NAME.jar &
        ps -Ao pid,command | grep java | grep $PROGRAM_NAME.jar | awk '{print $1}' > $PIDFILE
        echo
}

application_stop() {
        echo -n "Stopping $PROGRAM_NAME daemon..."

        if [ -r $PIDFILE ]; then
                PID=`cat $PIDFILE`
                if [ $PID -gt 0 ]; then
                        kill $PID
                        echo
                        sleep 1
                        fi
                rm -f $PIDFILE
        fi
        killall $PROGRAM_NAME
}

application_restart() {
        application_stop
        sleep 1
        application_start
}

case "$1" in
'start')
        application_start
        ;;
'stop')
        application_stop
        ;;
'restart')
        application_restart
        ;;
*)
        echo "usage $0 start|stop|restart"
esac
Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
  • I want to bring the java application to front of the user by using process name like (wmctrl -a "Mozilla Firefox"),but for java application wmctrl is not working.Can we get the java application to front by using process id instead of process name. – ruhil Apr 05 '13 at 13:55
  • I really don't know, here is the documentation http://linux.die.net/man/1/wmctrl but looks like they only can show list of PID of windows... – Alexandre Lavoie Apr 05 '13 at 15:17
0

Solution

If you run your command in the background (add & at the end), you can get the PID of using $! :

PID (process ID) of last job run in background

Command

java -jar app.jar &; echo $!
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
  • I want to bring the java application to front of the user by using process name like (wmctrl -a "Mozilla Firefox"),but for java application wmctrl is not working.Can we get the java application to front by using process id instead of process name – ruhil Apr 05 '13 at 13:57
  • That's something different from what you originally asked. Try a new question – Édouard Lopez Apr 05 '13 at 15:07