Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to list only running application like: firefox, gedit, nautilus etc. by command-line.

Note:- I don't want to list all running process. But only list application which is running (say manually launched GUIs).

share|improve this question
2  
"only list application which is running" what do you mean? all applications (known also as processes) are running. You mean only opened windows, like 'firefox, empathy and thunderbird' or all process that your user started like 'unity, compiz, gnome-terminal, apt-get'? –  Braiam Jun 15 at 13:39

3 Answers 3

up vote 3 down vote accepted

A combination of wmctrl and xprop offers many possibilities.

Example 1:

running_gui_apps() {

    # loop through all open windows (ids)
    for win_id in $( wmctrl -l | cut -d' ' -f1 ); do 

        # test if window is a normal window
        if  $( xprop -id $win_id _NET_WM_WINDOW_TYPE | grep -q _NET_WM_WINDOW_TYPE_NORMAL ) ; then 

            echo "$( xprop -id $win_id WM_CLASS | cut -d" " -f4- )"", window id: $win_id"

        fi

    done
}

The output could look in this case similar like this:

"Firefox", window id: 0x032000a9
"Gnome-terminal", window id: 0x03a0000c
"Thunar", window id: 0x03600004
"Geany", window id: 0x03c00003
"Thunar", window id: 0x0360223e
"Mousepad", window id: 0x02c00003
"Mousepad", window id: 0x02c00248
"Xfce4-terminal", window id: 0x03e00004

Example 2:

running_gui_apps() {
    applications=()

    # loop through all open windows (ids)
    for win_id in $( wmctrl -l | cut -d' ' -f1 ); do 

        # test if window is a normal window
        if  $( xprop -id $win_id _NET_WM_WINDOW_TYPE | grep -q _NET_WM_WINDOW_TYPE_NORMAL ) ; then 

            # filter application name and remove double-quote at beginning and end
            appname=$( xprop -id $win_id WM_CLASS | cut -d" " -f4 )
            appname=${appname#?}
            appname=${appname%?}

            # add to result list
            applications+=( "$appname" ) 

        fi

    done

    # sort result list and remove duplicates  
    readarray -t applications < <(printf '%s\0' "${applications[@]}" | sort -z | xargs -0n1 | uniq)

    printf -- '%s\n' "${applications[@]}" 
}

Output example:

Firefox
Geany
Gnome-terminal
Mousepad
Thunar
Xfce4-terminal

You can add the function to your ~/.bashrc or run it from an script file.

share|improve this answer

wmctrl -l could be a thing you wanted. First install it

sudo apt-get install wmctrl

You can also combine it with System Monitor's list, by default it shows "All my processes" which means all process that belong to you as a user.

To have only names of applications, run:

EDIT:

wmctrl -l|awk '{$3=""; $2=""; $1="";  print $0}'
share|improve this answer
    
OP wants to get only the application name. Is this possible? –  Avinash Raj Jun 15 at 13:04
    
no, i opened firefox browser. Your command shows 0x03c000b3 0 avinash-Lenovo-IdeaPad-Z500 How list of running applications by command? - Ask Ubuntu - Mozilla Firefox plus some extra lines about Desktop,Hud,etc. –  Avinash Raj Jun 15 at 13:29
    
@AvinashRaj: sorry, I am working on it, I will add asap an edition, thanks for your attention –  Ruslan Gerasimov Jun 15 at 13:31
    
@AvinashRaj this is an addition, wmctrl -l|awk '{out=""; for(i=2;i<=NF;i++){out=$out" "$i}; print $out}', will add to my answer. Thank you for pointing out. –  Ruslan Gerasimov Jun 15 at 13:43
    
sorry , won't works for me. –  Avinash Raj Jun 15 at 13:52

If I want to see all or search for certain processes I'll use ps aux or ps aux | grep firefox for example.

share|improve this answer
    
i opened firefox application but ps aux | grep httpd displays nothing. –  Avinash Raj Jun 15 at 12:58
1  
because grep httpd is searching for only httpd service ;) just do ps u –  Tomanow Jun 15 at 12:59
    
It display bash only but i opened firefox application also. –  Avinash Raj Jun 15 at 13:01
    
to see firefox process do ps aux | grep firefox –  Tomanow Jun 15 at 13:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.