How to check which program is running inside gnome-terminal

I want to write a program that prints the current focused window name, and if it is a gnome-terminal, then prints the running program inside the current gnome-terminal tab (for example, vim if a vim session is running).

To get the current focused window name, I used:

xprop -root | grep "_NET_ACTIVE_WINDOW (WINDOW)"

     

xprop -id 0x220ad5a | grep "WM_CLASS (STRING)"

If the current window is a gnome-terminal, this will return 'gnome-terminal'.

But how can I find out the program running inside the gnome-terminal (more precisely: inside the current gnome-terminal tab)? I was thinking about using dbus, but gnome-terminal does not seem to support it.

+3
source share
2 answers

Get the PID of the gnome terminal and check which processes have this number as PPID.

I answered a very similar question a few days ago, see this link for details.

0
source

Thanks Adam! I'm almost there. With xprop, I can get the PID of the gnome terminal (6736). But, unfortunately, there is only one process for all windows and tabs of gnome-terminal. See this pstree output with two gnome-terminal windows open:

 -gnome-terminal(6736)-+-bash(6738)---vim(6780) 

  |                    |-bash(7026)---pstree(7045) 

  |                    | `-{gnome-terminal}(6740) 

Is there a way to find out the bash pid of the current open gnome-terminal tab?

0
source

Source: https://habr.com/ru/post/1729765/


All Articles