9

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.

Andrew
  • 191
  • If you Quit iTerm2 will it not quit all processes? – Ruskes Sep 12 '14 at 02:17
  • @Buscar웃 yes, it wouldn't quit them. I've just added steps to reproduce to question. – Andrew Sep 16 '14 at 15:41
  • Do you have tmux integration turned on? If so, it's probably creating tmux sessions for every tab you open. Try tmux list-sessions and see what it comes back with. – Jay Thompson Sep 16 '14 at 15:48
  • @JayThompson I don't use tmux, but I have it installed, list-sessions tells me failed to connect to server: No such file or directory – Andrew Sep 16 '14 at 16:15
  • Hm. Does it also happen for non-Ruby processes? e.g. top – Jay Thompson Sep 16 '14 at 16:54
  • same for me, just installed iterm2 and appreciated the features and right after that ran into several major bugs (what a shame) – igor Sep 21 '16 at 12:22

2 Answers2

8

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.

Libin Wen
  • 181
  • 1
    you have only 5 seconds to undo before iterm2 kills process for real though – igor May 14 '19 at 11:33
  • @igor You can change the time limit. The default is 5 seconds, but this is a configurable feature in the iTerm2 Preferences / Profiles / Session / "Undo" can revive a session that has been closed for up to 5 seconds – AFK Apr 13 '21 at 17:32
-2

I know its super old, but incase anyone else comes across this: Ctrl+C worked for me in iterm2

fsb
  • 22,799
guest
  • 9