Currently running applications in Linux

Ingila Ejaz picture Ingila Ejaz · May 31, 2012 · Viewed 8k times · Source

I'm working on a project similar to what we call system monitor in Linux. I'm using opensuse 11.4 gnome. I was wondering if there's any command (Except ps) that lists all currently running applications on the system. I'm developing it for multi-core environment.

For example I'm browsing the web with Firefox and lets say Google Chrome simultaneously, plus I'm editing text in a text file. In this scenario, when I open my project, I want the list of all applications currently running [in my scenario, the names gEdit, Google Chrome and Firefox(but not the process these three apps generated) must be displayed as a list]

The output I want is the same as what we get in the Applications tab when we use task manager in Windows.

If anyone has a solution, please let me know it'll be highly apprecieted. I'm using netbeans to implement the project. Thanks!!!

Answer

happenpappen picture happenpappen · May 31, 2012

I don't think there is a easy way of getting this done. In Linux an application may create several processes on startup - for example let's take postfix:

localhost:~ # ps -ef|grep postfix
 root      3708     1  0 Apr24 ?        00:00:35 /usr/lib/postfix/master
 postfix   3748  3708  0 Apr24 ?        00:00:01 qmgr -l -t fifo -u
 postfix   3749  3708  0 Apr24 ?        00:00:00 pickup -l -t fifo -u -c
 postfix  13504  3708  0 16:05 ?        00:00:00 cleanup -z -t unix -u -c
 postfix  15458  3708  0 17:45 ?        00:00:00 cleanup -z -t unix -u -c
 postfix  19907  3708  0 19:25 ?        00:00:00 cleanup -z -t unix -u -c

the processes "master", "qmgr", "pickup" and "cleanup" all belong to the application postfix. You can see that those processes each belong to one parent process "master" by looking at the third column which tells you the parent process who has startet this process. In my example all processes have been startet by process with id 3708. Another example is the Apache Webserver, which creates several httpd processes on startup - here the process names are all the same only the count varies depending on the configuration.

To come back to the problem you would like to solve: From my point of view there are two ways you could try:

  1. Build up a database which contains associations of processes names to applications and use this to create your list of applications by using ps.
  2. You restrict your application to list only applications which display a graphical user interface. This list should be easily build by using some X11 functions or the likes...

hope this helps...