WSL icon indicating copy to clipboard operation
WSL copied to clipboard

disowned XTerm process should remain running when 1st bash exits

Open jamesdavidhoward opened this issue 9 years ago • 7 comments

After starting a process from the 1st (& only) running bash shell, I can use the disown built-in shell command to (supposedly) divorce the 2nd process from the 1st and make it immune from the termination of the 1st bash process. (This works OK on "real" Linux.) However, it appears that in WSL, that the whole subsystem is terminated when this 1st bash shell is killed (as by exit).

I understand that there is arguably little reason to continue the life of the WSL subsystem after the very last Linux process has exited. However, any started, then disowned, process is still a working, valid Linux process. (In this case, it was xterm, talking to a local Windows-native X11 Server, and displaying on-screen as a command line window - itself running its own bash shell.) When the bash shell running in a WSL console command-line window exits, it should not take the xterm with it!

The still-running xterm should be enough to keep the WSL subsystem aware it is needed, and to be kept running, supporting the xterm (and any other processes that have been started).

jamesdavidhoward avatar Dec 16 '16 08:12 jamesdavidhoward

This is how the system works right now by design, although they have fixes on the backlog. The workaround is using something called run.exe (search the issues page). Please close.

fpqc avatar Dec 16 '16 08:12 fpqc

That is not my understanding; the lifetime of the Linux-supporting WSL subsystem was supposed to run as long as there were running Linux processes. (The issue of starting daemons or other services, without 1st invoking a bash shell is a different thing. That daemon/services issue is what I understood to be Backlogged, as commented by MSFT's Rich Turner [@richturn_ms]...)

jamesdavidhoward avatar Dec 16 '16 08:12 jamesdavidhoward

Nope, you need to have at least one Linux process attached with active io handles to at least one Windows console (and the solution is basically to have Windows hide the console). The service counts for active handles, and when all active handles are gone, it shuts itself down.

fpqc avatar Dec 16 '16 09:12 fpqc

@jamesdavidhoward -- my understanding matches that of @fpqc .

There's a UserVoice here requesting the behavior that you are assuming, as well as proposing some workarounds.

aseering avatar Dec 17 '16 00:12 aseering

A shortcut to the .vbs file below with the command you want to run (I suggest bash -c 'sleep Infinity' to avoid accidentally killing it) as an argument will run the command prompt hidden.

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

Alternatively, you can use either cerebrate/wabash, the run.exe mentioned by @fpqc, or something like my startwsl.vbs. Any of these will give you a persistent session, which will allow you to run processes in the background, though I recommend a vbs script as it's a single-file that's easier to modify and copy to other computers.

Efreak avatar Dec 18 '16 01:12 Efreak

@Efreak If you're on 14986, you can do your session as opening tmux maximized (not suggested on earlier builds due to pty bugs).

fpqc avatar Dec 18 '16 03:12 fpqc

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

Brian-Perkins avatar Nov 22 '17 18:11 Brian-Perkins