• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to capture the PID when instantiating for a Java program  RSS feed

 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a UNIX script that executes a Java program - HlpValXls2, which in turn executes another Java program, ie HlpValOraBufXm1, 1 of those six below, and i'm trying to figure out how to capture the PID id for each job or instantiation!

The problem is, a user may end up submitting the same job more than once and not know it, because of running in background mode!

I've tried some of the examples in this link:

http://www.coderanch.com/t/109334/Linux-UNIX/UNIX-process-ID-java-program

but because i'm running the Java programs from another Java program, i'm not sure if i can use the 'exec' command in the Process class!

Any ideas would be greatly appreciated!

Thanks much!

 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i'm going to try to use the coding technique referenced in my previous email!

As we all now know, posting on the Ranch makes for great 'step back and re-tack' therapy sometimes!

I basically going to put that program selection code into a script, pass the correct array value and call the program from a script and hopefully capture the PID!

But if you can think of a way to capture the PID without using an external script, i'd appreciate hearing about it!

Thanks!
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes this works fine!

import java.io.*;

public class CC
{
BufferedReader stdout;
Process myProcess;
InputStream is;
InputStreamReader isr;

public CC()
{
String cmd = "rtn";

try {
myProcess = Runtime.getRuntime().exec("/home/xxxxxx/rtn");
is = myProcess.getInputStream(); stdout=new BufferedReader(new InputStreamReader(is)); String line = stdout.readLine();
while (line != null) { System.out.println(line); line = stdout.readLine(); }
int exitVal=0; try { exitVal = myProcess.waitFor(); } catch(InterruptedException ie) {System.out.println(ie);}
System.out.println("exit value: " + exitVal);
} catch(IOException ioe) {System.out.println(ioe);}

}

public static void main(String args[])
{
CC run = new CC();
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!