Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmux sessions not kept across bash exits #2252

Closed
KireinaHoro opened this issue Jun 24, 2017 · 9 comments
Closed

tmux sessions not kept across bash exits #2252

KireinaHoro opened this issue Jun 24, 2017 · 9 comments

Comments

@KireinaHoro
Copy link

  • Your Windows build number: (Type ver at a Windows Command Prompt)

10.0.15063

  • What you're doing and what's happening: (Copy&paste specific commands and their output, or include screen shots)

Detach from a session and exit bash and powershell. Open up powershell and bash again and try to attach back and one will see a "no sessions" error (nothing shows up when executing tmux list-sessions)

  • What's wrong / what should be happening instead:

Sessions should be kept as long as the system stays on and in a reasonable state.

  • Strace of the failing command, if applicable: (If <cmd> is failing, then run strace -o strace.txt -ff <cmd>, and post the strace.txt output here)

(inapplicable)

@sunjoong
Copy link

@KireinaHoro - Quote from
https://www.reddit.com/r/bashonubuntuonwindows/comments/50n54z/tmux_sessions_killed_on_bash_exit/

In the current design, all lxss processes are killed when the last bash window exits. You will want to have something run in the background to continue your tmux session.

@KireinaHoro
Copy link
Author

@sunjoong thanks for the thread quote.

Yet simply keeping a window open is a rather awkward workaround for the situation. Is it possible to elevate tmux to a system service (sshd for example)? Will this work?

@sunjoong
Copy link

sunjoong commented Jun 24, 2017

Yet simply keeping a window open is a rather awkward workaround for the situation.

@KireinaHoro - Hmm... Yeah, that looks awkward but think like this; If WSL be a linux box, what's the booting up and what's the shutting down? I think no running bash process might be similar to shutdown status. And... for system service... https://superuser.com/questions/1112007/how-to-run-ubuntu-service-on-windows-at-startup and http://webkempers.com/wsl-auto-start-workaround .

You don't need sshd on this workaround, so... hmm... might this work? I'm not sure but making only one bash process alive you need, so... try to add this to Windows's Task Scheduler but don't belive me :)

set ws=wscript.createobject("wscript.shell")
ws.run "C:\Windows\System32\bash.exe -c 'while true; do sleep 3600; done'",0

@rodrymbo
Copy link

I've had trouble with the ws option because wscript.exe it is a 32-bit program which looks in SysWOW64 instead of System32 for bash.exe, and of course bash.exe is not there. (Yes, it appears backwards the first time you see it ... the system-level substitution of SysWOW64 for System32 for 32-bit programs seems to be transparent, so unless you look for it you won't notice.)

The solution seems to be to use c:\windows\sysnative\bash.exe if the system32 version doesn't work, though I can't remember where it is documented.

One can also use the run.exe program from the xming site to start a bash window hidden. Advantage: the window is not around to close accidentally. Disadvantage: it's hard to close it from Windows. (From within bash.exe, sudo kill will do the trick, and as soon as the last process is closed, the hidden bash.exe window will also close.

@sunjoong
Copy link

@rodrymbo - Thans. On my Windows 10 Home edition, wscript.exe is in C:\Windows\System32 directory and in C:\Windows\SysWOW64 directory too, so I guessed that might work :)

@rodrymbo
Copy link

rodrymbo commented Jun 26, 2017

@sunjoong - Ooh. When did that happen? Looks like Microsoft is catching up with itself.

Anyway, it took me a while to figure out why some programs were getting "The system cannot find the file specified" for c:\windows\system32\bash.exe. It will be excellent if no one has to go through that again! But I suspect it will be good scripting style for a while yet to do a test for existence before invoking bash.exe, just to be sure, and so you've got a start at figuring out what is going on.

And it does look like invoking bash.exe via VBS is a good way to keep the window hidden (if that's what you want).

And yes, if you use that technique to launch a script that runs, say, cron, or sshd, or @sunjoong's loop, and waits, the window will stay open but running, the WSL subsystem will keep running, and there's a good chance background programs or tmux started later will keep running, even if their window is closed.

@Brian-Perkins
Copy link

Windows Insider Build 17046 allows programs to execute without an active terminal.

@benhillis
Copy link
Member

Fixed in 1803.

@kundeng
Copy link

kundeng commented Mar 20, 2019

Not fixed.
tmux session lost when closing the bash window

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants