In general this should be fine to do it this way.
When you click the "X" to close the terminal window, that is sending a "signal" from your desktop (GNOME, KDE, etc.) to the terminal application, telling it to shut itself down. Since you're running MATLAB in this shell it's considered a child process to the terminal application.
So part of the responsibilities of being a parent process, is that you in turn send this same close "signal" to your children.
Now if you understand conceptually what I just explained then let's substitute in a bit more of the real terminology.
signals
First with the "signal", there are actually a whole family of different signals that you can send to Unix processes. To keep it simple there are 4 that you'll often see, SIGHUP
, SIGTERM
, SIGINT
, and SIGKILL
.
SIGHUP
The SIGHUP signal is sent to a process when its controlling terminal
is closed. It was originally designed to notify the process of a
serial line drop. In modern systems, this signal usually means that
controlling pseudo or virtual terminal has been closed.
SIGTERM
The SIGTERM signal is a generic signal used to cause program
termination. Unlike SIGKILL, this signal can be blocked, handled, and
ignored. It is the normal way to politely ask a program to terminate.
SIGINT
The SIGINT (“program interrupt”) signal is sent when the user types
the INTR character (normally C-c).
SIGKILL
The SIGKILL signal is used to cause immediate program termination. It
cannot be handled or ignored, and is therefore always fatal. It is
also not possible to block this signal.
NOTE: SIGINT
is what gets sent when you use Ctrl+C to "break" a program from the command line while it's in the middle of running.
which one is getting used?
Most likely the SIGTERM
is being called by your windowing environment and being passed down to your terminal. Your terminal is then most likely then sending SIGHUP
down to MATLAB. This signal gives all the processes the opportunity to do any local clean-up (closing files, ending processes, etc.) themselves.
kill command
You can send signals yourself using the poorly named command, kill
. So to send the SIGTERM
signal to your terminal or the SIGHUP to MATLAB, you could determine their PID using
ps` and then run this command to send them the signal:
$ kill -SIGTERM <PID>
or this:
$ kill -SIGHUP <PID>
You can get a complete list of the signals using this command:
$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
...
...
Notice that the signals have numbers? You'll often times see them used like that instead of by their names:
$ kill -15 <PID>
Or the infamous -9
, which can kill pretty much any process.
Non-printable sequences should be enclosed in \[
and \]
. Looking at your PS1 it has a unenclosed sequence after \W
. But, the second entry is redundant as well as it repeats the previous statement "1;34".
\[\033[01;32m\]\u:\[\033[01;34m\] \W\033[01;34m \$\[\033[00m\]
|_____________| |_|
| |
+--- Let this apply to this as well.
As such this should have intended coloring:
\[\033[1;32m\]\u:\[\033[1;34m\] \W \$\[\033[0m\]
|_____|
|
+---- Bold blue.
Keeping the "original" this should also work:
\[\033[1;32m\]\u:\[\033[1;34m\] \W\[\033[1;34m\] \$\[\033[0m\]
|_| |_|
| |
+-----------+-- Enclose in \[ \]
Edit:
The reason for the behavior is because bash
believes the prompt is longer then it actually is. As a simple example, if one use:
PS1="\033[0;34m$"
1 2345678
The prompt is believed to be 8 characters and not 1. As such if terminal window is 20 columns, after typing 12 characters, it is believed to be 20 and wraps around. This is also evident if one then try to do backspace or Ctrl+u. It stops at column 9.
However it also does not start new line unless one are on last column, as a result the first line is overwritten.
If one keep typing the line should wrap to next line after 32 characters.
Best Answer
You can always try the obvious things like
^C
,^D
(eof), Escape etc., but if all fails I usually end up suspending the command with^Z
(Control-Z) which puts me back into the shell.I then do a
ps
command and note the PID (process id) of the command and then issue akill thePID
(kill -9 thePID
if the former didn't work) command to terminate the application.Note that this is not a tidy (no pun intended) way to terminate the application/command and you run the risk of perhaps no saving some data etc.
An example (I'd have used
tidy
but I don't have it installed):