Kill a Linux process programmatically in WSL2

If I issue a long-running WSL command from a C# program, how do I terminate that Linux process programmatically? How do I identify the PID of the process in Linux so that I can issue a ‘kill’ command?

On Linux I usually use ps xau | grep COMMAND. ps xau prints a list of running processes, the output then goes to grep which filters for lines matching the COMMAND. The second column is the PID. If you run just ps xau you get column labels at the top. :slightly_smiling_face:

I hope this works on WSL, too! :sweat_smile:

Thanks for your response, airtower-luna. At first, I wasn’t sure that you had read my question correctly, but after looking closely at your answer, I believe this will do exactly what I want.
Thanks again.

1 Like