aspose file tools*
The moose likes Java in General and the fly likes How to Get processes list from Remote Machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to Get processes list from Remote Machine" Watch "How to Get processes list from Remote Machine" New topic
Author

How to Get processes list from Remote Machine

Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Hi all,

Actually I need to know the running processes on remote server.

I must clear one thing that we don't have any access right problems for that server. We can access that server from my local machine.

Now what I want to do is designing of a graphical application in which User can have view to all processes running on that server machine, and according to the user right he/she can cancel/kill the process.

I have done some work besides of Swing designing for getting the list of processes of Local Machines. Here it is as follows.

[B][/B]

Now could anyone let me know, How to get the remote running(live) processes if we know the IP of that machine.

For this we can let suppose the IP of machine is XYZ.ABC.DEF.RDE.

Thanks in advance for replies.

[ March 14, 2007: Message edited by: Ankur Sharma ]
[ March 14, 2007: Message edited by: Ankur Sharma ]

The Best way to predict your future is to create it - Every great individual common man
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

Originally posted by Ankur Sharma:

Now could anyone let me know, How to get the remote running(live) processes if we know the IP of that machine.


Short of writing some service to run on the remote machine and provide you with a list, it cannot be done.


[How To Ask Questions On JavaRanch]
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Originally posted by Joe Ess:


Short of writing some service to run on the remote machine and provide you with a list, it cannot be done.


Thanks Joe for prompt reply.

Cann't you suggest me a short and sweet way to get run this sort of application.

I have already eloborated my application, I want to show the user to show those selected running application. And then user may start it either from remote or from local machine.

I have idea of using JSP's and Servlets.

Would it be a right solution, if I write the main logic into servlets and then try to access it and then start/end those application from JSP's by some flag process.

Do suggest me if you guys have any other better idea for this application.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

That would be fine, yes. A servlet could use Runtime.exec("tasklist") to get the list of processes and then display them in a form that let the user select processes to kill. When the form was submitted, the servlet (or another one, of course) receiving the form could then use Runtime.exec() to execute whatever Windows program you can run to kill a process (I'm assuming there is one.)


[Jess in Action][AskingGoodQuestions]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Would it be a right solution, if I write the main logic into servlets and then try to access it and then start/end those application from JSP's by some flag process.

Do suggest me if you guys have any other better idea for this application.

Is this a Windows only solution? If so why are you using Java at all? You can administer remote services with the tools Microsoft already supply.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Originally posted by Paul Sturrock:

Is this a Windows only solution? If so why are you using Java at all? You can administer remote services with the tools Microsoft already supply.


No Paul,

This is not basically used for windows environment. It would be used for Unix machine.

One more concern when I used the same program to run on Unix Machine with command ps -ef|grep java. Which will list all the running java programs. It was not working.

Can anyone explain this command ps -ef|grep java.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19004
    
  40

Can anyone explain this command ps -ef|grep java.


This is actually *two* commands. The "ps" command is providing the list of tasks. The output of that command is piped to the "grep" command which is getting rid of every line that doesn't have "java" in it.

If you want to get this to work, you may have to run a "sh" command, passing these two commands as parameters, as you need a shell to setup the pipes.

IMHO, I would recommend just using the "ps -ef" command. Once you get the output stream of the command, you can filter to what you need with Java. No need for another "sh", or the "grep" command.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

This is simple on linux. You just ssh into the remote machine, and execute your command there as if you are local. My Mandriva Linux and I assume every other Linux out there already does this. I can display, memory, file usage, cpu usage, network usage, all that good stuff for the local machine. To display it for a remote machine I first connect to it through ssh.

Perhaps you can do that. Its more secure and should abstract you from much of your code to have to know the data is coming remotely. and for the local machine you can 'ssh localhost' for consistency.


as Henry said "ps -ef|grep java" is two commands. Seperated by a 'pipe' which is represented by '|'. The data from ps -ef is piped into 'grep java'. This is the same technique that you would use to pipe your command through the ssh tunnel so it is executed remotely.

I dont know right off hand how to do it, and my computer here termprarily does not have ssh so I cant check it.
[ March 14, 2007: Message edited by: Mr. C Lamont Gilbert ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Get processes list from Remote Machine