Issue
I am using .NET core on Debian.
Trying to get list of all services and their status. (Equivalent to service --status-all
)
I tried System.ServiceProcess.ServiceController.GetServices()
but it seems to be Win32 only.
There is System.Diagnostics.Process.GetProcesses()
in .Net COREFX libraries which gives me a list of all processes (including service processes like cron).
How to?
- Distinguish which processes are running as a service.
- Get just a list of services and their statuses.
Solution
There is no such tooling in .NET Core. Linux/Unix/BSD specific behavior (like service management) was shifted to later releases (if at all).
In classic Unix/Linux there is no way to determine if a process is a service. Each service use a different way (user, process group, background, parent pid, ...). Also the service status cannot be determined. This situation is even more complicated with systemd which can do on-the-fly service activation when certain ports get activated. However, do not expect anything standardized like the Windows Services.
To figure out, how you can determine which process is a service, you need to ultimately consult the Debian documentation and may invoke a command line utility instead of an API method.
Answered By - Thomas Answer Checked By - Robin (WPSolving Admin)