• Post Reply Bookmark Topic Watch Topic
  • New Topic

List all running processes in Java code (MAC/Unix)  RSS feed

 
Katie McGettrick
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

Ok, this isn't strictly a java problem I think its more related to the fact that I'm very inexperience when it comes to the mac/unix environment.

Basically part of an application that I'm writing in Java needs to check if another application is still open in order to move on to the next step. What I'm doing on windows is using Runtime.exec and tasklist, getting the imput back with the InputStreamReader and then checking for the process. On windows this works great. In my ignorance I thought that for the mac I could just use the ps command but this still has the process listed even after the application has shut down. I don't know enough about how the mac handles processes so I don't know what I can do.

Does anyone know of another way I can do this using java or of a better way to use this ps command so I don't see these processes that are from applications that have been shut down. I have been examining the processes to see if there's any change in state when the Application is started up or shut down so that I could maybe exclude these in the code but I can't see a difference.

Anyone got any ideas?
 
Danish Sualeh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this issue could be approached from the point of view of Inter Process Communication.

Now lets see we could use RMI , Sockets ....

What if the first app which needs to synchronize itself (i.e check if the second app is running) tries to do so by establishing a socket connection with the other app.
In case it receives no response it will act accordingly.

So in the second app we could having a thread that can keep listening for connection at a particular port and respond with its status.

I feel this approach i.e Inter Process Communication , would even hold even if the two processes were on different machines.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!