• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

showing the OS processes(XP,Mac)

 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for 2), see SetWindowPos:
You can of course also add other flags, perhaps SWP_SHOWWINDOW.
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic