Gnome Terminal – What’s Going on in /usr/bin/gnome-terminal

gnome-terminal

I noticed that there were no processes named "gnome-terminal" although I was using so called "gnome-terminal" which was invoked by clicking the icon on the menu bar on desktop.

$ ps -au | grep gnome
cul8er    8763  0.1  0.8 554960 33268 pts/22   Sl   05:16   0:00 /usr/lib/gnome-terminal/gnome-terminal-server --app-id com.canonical.Terminal.AnAuzDeiSeoqQhlGKbPNPeHhAROwBwtP
cul8er    8771  0.0  0.0  14852  1832 pts/22   S    05:16   0:00 gnome-pty-helper
cul8er    8821  0.0  0.0  14656  2232 pts/23   S+   05:27   0:00 grep --color=auto gnome

So I typed gnome-terminal &. the output was the following:

$ gnome-terminal &
[2] 8865
$ 
[2]+  終了                  gnome-terminal
$ echo $LANG
ja_JP.UTF-8

This result seems to show that the process of gnome-terminal exited immediately when the terminal emulator was displayed.
If it is true, why can I see new terminal without a process associated to it?

So I checked the command gnome-terminal:

$ which gnome-terminal
/usr/bin/gnome-terminal
$ file /usr/bin/gnome-terminal
/usr/bin/gnome-terminal: Python script, ASCII text executable

gnome-terminal is a python script.

I looked at it. I couldn't understand enough because I don't know python, however I noticed /usr/lib/gnome-terminal/gnome-terminal-server --app-id, which was shown in the output of ps, is related to this issue. But I don't know what does 'subprocess' and 'Popen' mean.

subprocess.Popen(['/usr/lib/gnome-terminal/gnome-terminal-server',
                           '--app-id',
                           name],
                          stdout=subprocess.DEVNULL,
                          stdin=subprocess.DEVNULL,
                         stderr=subprocess.DEVNULL)

If sub processes are invoked whenever gnome-terminal script runs, multiple processes should run when I open gnome-terminals. However it always seems that there is only one process /usr/lib/gnome-terminal/gnome-terminal-server --app-id in ps's output.

What is going on while the script runs?

And where is the process that represents so called "gnome-terminal"?

OS: Ubuntu 15.04

Best Answer

The single process /usr/lib/gnome-terminal/gnome-terminal-server is the process handling all of your gnome-terminal windows.

The command gnome-terminal fires up gnome-terminal-server if it's not already running, or connects to the existing instance and asks it to open a new window.

If each invocation of the command gnome-terminal opened a new window itself and so each terminal window was handled by its own separate process, you wouldn't be able to drag-n-drop tabs across them. This is I belive the most important reason behind this design. There might be other reasons as well, I'm not sure.

Related Question