'Get child processes of a main process without System.Management

Trying to get process information of dotnet core services that are actively running.

Services on Linux for dotnet are done like;

ExecStart=/bin/bash -c 'PATH=/sbin/dotnet:$PATH exec dotnet /path/to/dotnetcore.dll'

We're getting all processes by going:

foreach (var p in System.Diagnostics.Process.GetProcesses()) {}

For each process the ProcessName value is dotnet, and can get the memory size, etc. But when there are multiple services that are running via dotnet we don't know which service it's associated to, as the ProcessName is just dotnet.

Current answers out on the Internet use System.Management which is not supported on Linux.

I know I can use a workaround with bash execute systemctl status <servicename> or systemctl show <servicename> and then grep the output. But I'm looking for a modern solution, in purely .Net code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source