iTerm2 does not kill processes when tab is closed

If I work in terminal, and, say run rails server in it attached to the current terminal and then close the tab it will not terminate the process making it hang around indefinitely without ability to bring it. Is it possible to fix it?

Steps to reproduce:

  1. Open new terminal tab (cmd + t);
  2. Run a process in it (e.g. irb);
  3. Close the tab (cmd + w);
  4. List processes to see that irb is still running (ps ax|grep irb).

Quitting iTerm doesn't finish these processes either.


I think it is supposed to be a feature instead of a problem.

Generally, to kill a process or just exit the current shell session, you should not use "cmd+w" or click the close button of the window. Instead, you should use "ctrl-c" and "ctrl-d" respectively.

Besides, the following facts may help you,

  • You can use "cmd+z" to fully restore a tab right after it is closed
  • The attached session and tasks keep run in background right after you close a tab. You can restore the tab at this point. But if you open a new tab using "cmd+t" now, the background session in the previously closed tab will be killed.

So the "restorable tab closing" is a feature of iterm2, though quite confusing.