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

How can I find out the bash PID from a Windows cmd/powershell prompt? #3174

Open
rfgamaral opened this issue May 10, 2018 · 10 comments
Open
Labels

Comments

@rfgamaral
Copy link

Say I have the Windows PID from the bash process when running a WSL instance. Is it possible to get the bash process PID using cmd/powershell?

image

How can I use the 7100 in this example, to get the 3?

@Biswa96
Copy link

Biswa96 commented May 10, 2018

Then run: bash.exe -c "lsof" | find "bash"

@Brian-Perkins
Copy link

There is no easy way to map between the two ID's. Currently this is mostly because we are not exposing it in any way, but beyond that there may not be a 1:1 mapping between the two due to things like clone flags. Additionally the mapping may not be static as we try to play nice with process monitoring tools (AV, et al.) by creating new NT processes in response to exec since that is how it is normally done from Windows.

@rfgamaral
Copy link
Author

rfgamaral commented May 10, 2018

@Biswa96
That will never work, you might have multiple bash processes running from different WSL instances.

@Brian-Perkins
Ok, time for context on why I asked this, maybe I should've done that from the start...

I recently started using Hyper and found a bunch of plugins that have problems with WSL, for instance:

The first two have basically the same issue, they need to read the current shell absolute path from Hyper and there's no proper way to do that. The third one depends on the current foreground process running in the shell (I'm not sure if this could be fixed even if we could read the bash PID).

In other words, to fix all these plugins properly, we'd need WSL to expose the current absolute path and running process and somehow map it properly per Windows PID (because Hyper is tabbed and we can have multiple WSL instances running).

Given the current state of WSL I couldn't think of any way to get these plugins to work with WSL. Thoughts?

@fpqc
Copy link

fpqc commented May 12, 2018

@rfgamaral Are you running hyper over X, or are you running the Windows version? If the Windows version is compatible with cygwin, you can probably use rprichard's WSLbridge, which pipes the terminal through to a cygwin pty.

@rfgamaral
Copy link
Author

@fpqc I'm using the Windows version. However, I'm not sure the PID mapping between Windows and the running bash instance inside WSL can be done like @Brian-Perkins mentioned.

@therealkenc
Copy link
Collaborator

It is something that would have to be implemented in the plugin, which is crossing a boundary. Brian mentions Linux PID namespaces and multiple WSL instances, but it is more straightforward to think of hyper in a ssh session. Javascript on Windows has no idea what the PIDs are over on the remote machine. It would be like asking a DEC VT100 firmware programmer in 1978 to tell you the PID or path of the shell on the other end of the RS232 wire.

This said, there needs to be some API to expose the mapping. /proc/[pid]/win-pid seems like a reasonable ask.

@therealkenc
Copy link
Collaborator

Someone opened a UserVoice here.

@dmex
Copy link

dmex commented Jun 8, 2018

This ticket is also related to winsiderss/systeminformer#153

We also need something to map the NT processid to the WSL processid to implement those missing features (this also applies to the same features in Task Manager and Process Explorer).

One example is right-clicking a process in Task Manager/Process Explorer/Process Hacker and selecting the Debug menu to launch the debugger (e.g. WslLaunchInteractive("gdb -p PID")) but this requires the distro name and pid.

@benhillis

Are you able to follow this up?

@therealkenc
Copy link
Collaborator

Ref #6881

@CervEdin
Copy link

CervEdin commented Jan 25, 2023

This said, there needs to be some API to expose the mapping. /proc/[pid]/win-pid seems like a reasonable ask.

In mingw I believe its /proc/[pid]/winpid

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

7 participants