List of running applications/programs


Is there a way to get a list of running applications (not processes) in C++. I tried experimenting with ps from bash, but can't figure out how to select just the running programs filtering out non-application processes.

If this is possible, is there a way to switch to a particular application using the pid or some other method.

The purpose of the above is to create a task manager that would work with all window managers.

Thanks for any suggestions.
You can't do what your asking.

The way to get the applications running within any given window manager would be to ask that window manager for a list of it's child processes. This would most likely be different for each window manager and not related to 'ps'.

I'd ask on the GTK forums and KDE forums about how to do it for each of those 2 window managers, but I would expect vastly different answers.
Thanks for you quick reply.

The purpose was to create a main menu (easy) and task switcher independent of any window manager or desktop environment. Its really not necessary in DE's like kde, gnome, xfce etc., but would be useful with the various window managers each of which are configured differently.

It's better to know it can't be done than to pursue something thats not possible.

Thanks Again

Don't give up so easily!

This is not as easy to do as you might hope, but it is completely doable. You may not be able to support any and all windows managers, but if you cover the bigger set (kde, gnome, xfce) and some of the smaller ones (fluxbox, blackbox, etc) then you can probably port it to any other WM fairly easily.

Looking for processes by looking at the tree and finding all children of the window manager won't work. Try playing with pstree in console and running a few applications to see where they end up on the process tree. Most of them end up being directly under init (the root process).

What you may have better luck doing is parsing the menu list in the window manager and displaying only processes that are in the menu as "applications".

If you have a particular set of applications that you would like to emulate, then look at the code for them and see what they do. The beauty of Linux is that you CAN go look at that code. Enjoy it! Gnome and KDE both have fully implemented programs for doing this, so learn from their code and implement the same concept on any other window manager that you would like to support. Since it has already been done, you know it's possible.

Just don't give up, and good luck :-)
Just don't give up, and good luck :-)


Thanks for your encoragement.
I'm just a "hobbyist" programmer who did a lot of playing with assembler and c/c++ in the 80's. Unfortunately, the only programming I've done recently was with Visual Basic (great RAD, krappy language), so I'm just getting reaquainted with C++. Although I played with linux in the late 90's, it wasn't until a year ago where it become my primary (99%) O/S., so I'm not a linux expert either but I've never been afraid of the console.
What I lack in brains, I usually make up in tenacity and don't give up without a fight. I know I will come back to it whenever an idea pops into my head (This is a curse not a blessing). I agree with you about learning from existing code. I've already started looking at MC (midnight commander) and openbox but thats going to take awhile to be able to piece everything together. I quickly looked at pstree which looks like a good learning and informational tool.

Thanks Again for the encouragement and information.

Topic archived. No new replies allowed.