• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

How to capture the PID when instantiating for a Java program

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

https://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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
Evacuate the building! Here, take this tiny ad with you:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic