File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes showing the OS processes(XP,Mac) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "showing the OS processes(XP,Mac)" Watch "showing the OS processes(XP,Mac)" New topic
Author

showing the OS processes(XP,Mac)

Girish Vasmatkar
Ranch Hand

Joined: Apr 24, 2008
Posts: 201
Hello to all,

I know that this questioned has been asken an umpteen number of times and its solution is also available but here is the twist:

1. I want to list the processes from the other OS as well. Like we can execute tasklist.exe using PrecessBuilder class but how about showing processes running on a Mac machine or on a Linux machine for that matter.

2. Also I would like to go a step further in a sense that I want to have the feature "bring to front" in the task manager. That will bring the selected window to the front.

I guess that for my second question I'll have to use JNI. Can some body tell me how can I accomplist the task. Or should i ask this way- is it even possible?

Regards,
girish
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41626
    
  55
For #1, the "ps" command is available on all Unix-based OSes. "ps a" includes all foreground applications, but it lists more processes than just those. So you may have to do some filtering of the list.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

As for 2), see SetWindowPos:
You can of course also add other flags, perhaps SWP_SHOWWINDOW.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Girish Vasmatkar
Ranch Hand

Joined: Apr 24, 2008
Posts: 201
Thank you very much Ulf and Rob,

I'll try to use ps command and will let you know if I stuck any where.


For the second one, do I need to call that function using JNI? Also I will have to get the process ID of the process which is selected and then use that to bring the window related to that process to the front. How can I do that?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

If you are only worried about the windows opened by your Java application, you can use Window.getWindows() to retrieve all windows, then use the toFront() method of Window.


If you want all windows present, then you'll have to go JNI again. The functions involved are:
- EnumWindows
- a callback function you wrote: BOOL CALLBACK XXX(HWND hwnd, LPARAM lParam) (the XXX is free to fill in)
- inside that callback function, IsWindowVisible to see if the window is not hidden and GetWindowText to get the caption / title


Edit: if you have the process ID, you can use the following instead of EnumWindows:
- GetCurrentThreadId
- EnumThreadWindows

There may be other ways I don't know of to get all threads of a process to replace the call to GetCurrentThreadId.

Edit 2: what was I smoking? GetCurrentThreadId is not going to help you. You'll need another way to get all threads of a process. I think this link can help you: http://blogs.msdn.com/oldnewthing/archive/2006/02/23/537856.aspx
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: showing the OS processes(XP,Mac)