Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2003

Tip: Looking for answers? Try searching our database.

getting the process ID from inside UNIX. (echo problem)

Thread view: 
Ferman - 11 Sep 2003 11:33 GMT
Hi,

I found a solution. I run a command by exec() on UNIX OS.

program part like this;
   try
   {
     String vCommand({"echo", "$$"});
     Process p = Runtime.getRuntime().exec(vCommand);
     BufferedReader br =
       new BufferedReader(new InputStreamReader(p.getInputStream()));
     int pid = Integer.parseInt(br.readLine());
     System.out.println(pid);
     p.destroy();
     p = null;
     br = null;
   }
   catch (java.io.IOException e)
   {
     System.out.println(e);
   }

But it is give me "$$" characters. I didn't obtain the process id. What is
the problem ?
OS: SunOS
Joona I Palaste - 16 Sep 2003 20:44 GMT
Ferman <ferhat_torgaloz@hotmail.com> scribbled the following:
> Hi,

> I found a solution. I run a command by exec() on UNIX OS.

> program part like this;
>     try
[quoted text clipped - 13 lines]
>       System.out.println(e);
>     }

> But it is give me "$$" characters. I didn't obtain the process id. What is
> the problem ?
> OS: SunOS

The "$$" is a feature of the shell. However, processes run with
Runtime.exec() run directly on the OS, not in any shell. Therefore
your solution won't work. You could try executing a batch file that
executed "echo $$ >somefile" and then read somefile back in on the
Java side, but I'm not sure if that gets you the correct process ID.
For the really adventurous, write your own shell, which has some kind
of interface to return its process ID. Then call that interface from
Java via JNI or something.

Signature

/-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"Hasta la Vista, Abie!"
  - Bart Simpson


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.