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

WSL spawns an extra shell process #11611

Closed
1 of 2 tasks
yacoob opened this issue May 23, 2024 · 8 comments
Closed
1 of 2 tasks

WSL spawns an extra shell process #11611

yacoob opened this issue May 23, 2024 · 8 comments
Labels

Comments

@yacoob
Copy link

yacoob commented May 23, 2024

Windows Version

Microsoft Windows [Version 10.0.22631.3593]

WSL Version

WSL version: 2.1.5.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.146.1-microsoft-standard-WSL2

Distro Version

Debian 12 bookworm

Other Software

No response

Repro Steps

  1. Install Debian via wsl.exe --install Debian, create thatuser account
  2. Run wsl via wsl -d Debian -u thatuser
  3. Run ps afux

Expected Behavior

There should be a single shell process that belongs to thatuser running on the system.

Actual Behavior

There are two shell processes running - one of them spawned by /init, handling the user interaction, the other spawned by /bin/login -f doing... something else.

root           2  0.0  0.0   2280  1300 ?        Sl   19:14   0:00 /init
root           8  0.0  0.0   2280     4 ?        Sl   19:14   0:00  \_ plan9 --control-socket 6 --log-level 4 --server-fd 7
root         136  0.0  0.0   2284   112 ?        Ss   19:14   0:00  \_ /init
root         137  0.0  0.0   2300   116 ?        S    19:14   0:00  |   \_ /init
thatuser     138  0.0  0.0   9732  3916 pts/0    Ss   19:14   0:00  |       \_ -bash
thatuser     172  0.0  0.0  13576  4304 pts/0    R+   19:18   0:00  |           \_ ps afux
root         139  0.0  0.0   4256  2692 pts/1    Ss   19:14   0:00  \_ /bin/login -f
thatuser     145  0.0  0.0   4188  3260 pts/1    S+   19:14   0:00      \_ -bash

Both of those shells are marked as a login shell. In another Debian 12 box I have access to, the process tree looks as expected: single login shell spawned by the login process:

root       73971  0.0  0.0   5800  3432 tty6     Ss   May22   0:00 /bin/login -p --
thatuser  211682  0.7  0.0  12564  6316 tty6     S    19:30   0:00  \_ -zsh
thatuser  211758  0.0  0.0  13568  4452 tty6     R+   19:30   0:00      \_ ps afux

Just for completness, I've tested how login -f works on a physical Debian12 box, and it did not spawn a second shell. From my cursory interrogation of /proc for both of those shells, they're both running in the same cgroup but different sessions. I have no idea how systemd perceives that due to #8879 .

Last but not least: mintty/wsltty#197 is very similar, except in my case I'm not using mintty at all :)

I'd appreciate some explanation around that second shell - why is it needed, what does it do, and - if it's a WSL thing - how can I get rid of it?

Thanks! :)

Diagnostic Logs

No response

Copy link

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The scipt will output the path of the log file once done.

Once completed please upload the output files to this Github issue.

Click here for more info on logging
If you choose to email these logs instead of attaching to the bug, please send them to wsl-gh-logs@microsoft.com with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

@yacoob
Copy link
Author

yacoob commented May 23, 2024

/question

Copy link

Diagnostic information
Found '/question', adding tag 'question'

@pmartincic
Copy link
Collaborator

pmartincic commented May 28, 2024

By design. You won't get rid of it. You're using systemd with wsl I assume?

Edit: double checked, use wsl without systemd if you don't want that there. It creates a systemd user session.

@yacoob
Copy link
Author

yacoob commented May 30, 2024

Thanks for the information, at least I know it's expected :) Is it documented anywhere?

@pmartincic
Copy link
Collaborator

It wouldn't be realistic for us to do that. So many pitfalls in doing that. We don't want people to rely on details like this. Details that are side effects of the implementation.

@yacoob
Copy link
Author

yacoob commented May 30, 2024

I was thinking primarily along the lines of "there's this extra shell as a result of WSL inner workings". At least we have this bug now :)

Thanks!

@gruffdavies
Copy link

gruffdavies commented Jun 11, 2024

I just spent the better part of an afternoon trying to figure out wtf this extra login was (concerned about security) and eventually came across this... I second @yacoob on the documentation. if this is normal behaviour for systemd but isn't documented as such then it's suspicious...

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

No branches or pull requests

3 participants