View Windows Process Information from Windows Subsystem for Linux

This blog post explains how a Bash shell script running under Windows Subsystem for Linux you can determine whether a process is running.

The Linux ps command can only see processes invoked by WSL. The Windows tasklist.exe command lists all Windows processes.

In WSL Bash shells running under Windows Terminal, I use the following function to open two .NET solutions with the JetBrains Rider Integrated Development Environment, which results in a single rider64.exe process and additional sub-processes.

function dev ()
{
    pkill -9 -f JetBrains;
    ide="/mnt/c/Program Files/JetBrains/JetBrains Rider 2021.1.2/bin/rider64.exe";
    "$ide" 'C:\temp\sln\HeadlessArchitect\HeadlessArchitect.sln' >> /tmp/rider.log 2>&1 & disown;
    sleep 15;
    "$ide" 'C:\temp\sln\DeliveryStack\DeliveryStack.sln' >> /tmp/rider.log 2>&1 & disown;
    sleep 1;
    pkill -9 -f JetBrains
}

For some reason, WSL sometimes thinks the rider.exe process is still running after Windows thinks it has stopped; the pskill commands clear up those ghost WSL processes. Even if you don’t disown and pkill the rider process, they remain active even if you close the Windows Terminal hosting the bash shell that launched it; the rider64.exe moves from being a descendant of Windows Terminal to being a root task.

Incidentally, if I don’t include the first sleep command, either something in rider throws a Java exception or it only opens one of the solutions, but that is irrelevant to the following.

Even though the rider64.exe process launched by WSL under Windows Terminal is still running in Windows, the Unix ps command cannot see the process, but the Windows tasklist.exe process can.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: