5

When you open gnome-terminal without any options and execute a blocking command (e.g. python3, vim or cat) and then try to close the window by the close button (i.e. x button in the title bar) or some keyboard shortcut, a confirmation window is displayed:

enter image description here

However, when you open gnome-terminal with an executed command specified, that is, in the form of gnome-terminal -- python3, the confirmation window is no longer displayed and the window is closed right after you (accidentally) click the close button.

Is it possible to show the confirmation window even when you use the form gnome-terminal -- <command>? If that's impossible, is there any workarounds?


Environments:

$ gnome-terminal --version
# GNOME Terminal 3.36.2 using VTE 0.60.3 +BIDI +GNUTLS +ICU +SYSTEMD

What I've Tried:

  • Equipping the executed command with signal handlers for all the supported signals didn't work; the window was still closed without confirmation although the process survived the closure while catching SIGHUP (three times), SIGCONT (once) and SIGWINCH (once). I had additionally to execute kill -SIGKILL <process id> to kill the process.

  • I found one exception. When you execute gnome-terminal -- bash, the confirmation is displayed (though this is by default the same as gnome-terminal).

ynn
  • 343
  • 3
  • 9
  • It is really great that MATE Terminal operates normally! You have to report (or find related) bug against GNOME Terminal on bugs.launchpad.net and maybe on GNOME GitLab. – N0rbert Jul 15 '20 at 11:44
  • Also python is not a "blocking" process. So it behaves as if you were running bash or another shell. It will, however, warn if some python script is actually running, just as when in bash, something is running. – vanadium Jul 15 '20 at 11:50
  • 1
    @N0rbert Which version of `mate-terminal` are you using? My `MATE Terminal 1.24.0` shows the same behavior as `gnome-terminal`. – ynn Jul 15 '20 at 11:56

1 Answers1

3

GNOME Terminal checks if there is foreground process started by shell (see terminal_screen_has_foreground_process function)

You can use sh to create new process and gnome-terminal to ask before exit this way:

gnome-terminal -- sh -i -c python3

Update: The same effect may be achieved with bash using custom script:

gnome-terminal -- bash -i my_script.sh

and the content of my_script.sh is just

python3
Mateusz
  • 349
  • 1
  • 5
  • Worked on Linux Mint but didn't work on Arch Linux. (On Arch Linux, `sh` is a link to `bash` while it is a link to `dash` on Linux Mint. However, even after installing `dash` and specifying `dash` explicitly, the code didn't work on Arch Linux. Trying to find the cause...) – ynn Jul 15 '20 at 14:00
  • My gnome-terminal version is `# GNOME Terminal 3.36.2 using VTE 0.60.3 +BIDI +GNUTLS +ICU +SYSTEMD` from Ubuntu 20.04. I tried this method with bash, and it didn't work, that's why I used sh. With bash I managed to achieve the same effect only using custom script: `gnome-terminal -- bash -i my_script.sh` and the content of my_script.sh is just `python3` – Mateusz Jul 15 '20 at 14:11
  • You are my hero. Please append the `my_script.sh` method in the answer? It worked like a charm. – ynn Jul 15 '20 at 14:18