The Artima Developer Community
Sponsored Link

Java Answers Forum
how to get processid in java.

3 replies on 1 page. Most recent reply: Oct 3, 2002 7:24 AM by Enric Jaen

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Trilok

Posts: 2
Nickname: thril
Registered: Jul, 2002

how to get processid in java. Posted: Jul 16, 2002 6:25 AM
Reply to this message Reply
Advertisement
i need to interact with the shell in the java program. and i need to get the processid of that process.
in c, we can get it using the system call getpid().
but how to get it in java. even by instantiating the java.lang.runtime and using the exec()method, i couldn't get the process id.
pls help me.


Chet Underwood, Esq.

Posts: 14
Nickname: chet
Registered: Mar, 2002

Re: how to get processid in java. Posted: Jul 16, 2002 11:32 AM
Reply to this message Reply
Just call java.lang.platform-specific.getProcessId(). It returns a variant, of course.

Trilok

Posts: 2
Nickname: thril
Registered: Jul, 2002

Re: how to get processid in java. Posted: Jul 17, 2002 4:06 AM
Reply to this message Reply
Thanks for the reply, but i couldn't find that java.lang.platform-specific.getProcessId()method in the API.and am using jdk1.3.1. do i need to use any latest version? pls. clarify.
Any way, i got someother option. i could find one package using which we can get the process id .the link is http://www.amug.org/~glguerin/index.html .

Enric Jaen

Posts: 1
Nickname: ejaen
Registered: Oct, 2002

Re: how to get processid in java. Posted: Oct 3, 2002 7:24 AM
Reply to this message Reply
Another way to get the processId is using a simple script containing:

#!/bin/bash
java your-classs &
echo $! > pidfile

and then you can read the pidfile from your java program:

BufferedReader pid =new BufferedReader(new FileReader("pidfile"));
System.out.println(pid.readLine());

Hope it helps,
-Enric

Flat View: This topic has 3 replies on 1 page
Topic: jdbc driver for mysql database Previous Topic   Next Topic Topic: Help with drag and drop

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use