Process manager for linux. It's can retrieve processes with linux specific info (uid of owner,gid of owner, executable path ...).
Help support the project:
Sample usage
var processInfos = ProcessManager.GetProcessInfos();
var initProcess = actual.FirstOrDefault(_ => _.ProcessName == "systemd");
Console.WriteLine($"Name: {initProcess.ProcessName}, " +
$"ProcessId: {initProcess.ProcessId}, " +
$"Real user id: {initProcess.Ruid}, " +
$"Effective user id: {initProcess.Euid}, " +
$"User name: {initProcess.UserName}, " +
$"Start time: {initProcess.StartTime}, " +
$"Process path (exe): {initProcess.ExecutablePath}");
Name: systemd, ProcessId: 1, Real user id: 0, Effective user id: 0, User name: root, Start time: 01.03.2018, Process path (exe): /lib/systemd/systemd
ProcessInfo[] processInfos = ProcessManager.GetProcessInfos();
ProcessInfo[] processInfos = ProcessManager.GetProcessInfos(new []{1,2,3});
ProcessInfo[] processInfos = ProcessManager.GetProcessInfos(_=>_.ProcessId == 1);
ProcessInfo[] processInfos = ProcessManager.GetProcessInfos(new []{1}, _=>_.ProcessName == "init");
ProcessInfo[] processInfos = ProcessManager.GetProcessInfoById(1);
int[] processInfos = ProcessManager.GetProcessIds();
IEnumerable<int> processInfos = ProcessManager.EnumerateProcessIds();
var initProcessCmdLine = processInfos.Select(_=>ProcessManager.GetCmdLine(_)).First();
var initProcessCmdLines = ProcessManager.GetCmdLine(1);
Console.WriteLine(initProcessCmdLines[0]);
/sbin/init
var pid = 1000;
var envVariables = ProcessManager.Instance.GetEnvironmentVariables(processId);
Console.WriteLine(envVariables["USER"]);
some_user
var pid = 1000;
var envVariables = ProcessManager.Instance.GetEnvironmentVariables(processId, _=>_.Key == "USER");
Console.WriteLine(envVariables["USER"]);
some_user
var pid = 1000;
var value = ProcessManager.Instance.GetEnvironmentVariable(processId, "USER");
Console.WriteLine(value);
some_user
var pid = 1000;
var signal = 9;//SIGKILL
ProcessManager.Instance.Kill(processId, signal);
ProcessManager.Instance.Kill(processId, ProcessSignal.SIGKILL);
var pid = 1000000; // not existing process
var result = ProcessManager.Instance.TryKill(processId, ProcessSignal.SIGKILL);
Console.WriteLine(result);
False
ProcessManager.Instance.Kill("some_process", "username", ProcessSignal.SIGKILL, (ex)=>Console.WriteLine(ex.Message));
ProcessManager.Instance.Kill("some_process", "username"); // signal SIGTERM
ProcessManager.Instance.Kill("some_process", 1001/*user id*/, ProcessSignal.SIGKILL, (ex)=>Console.WriteLine(ex.Message));
ProcessManager.Instance.Kill("some_process", 1001/*user id*/);// signal SIGTERM
ProcessManager.Instance.Kill((processInfo)=>processInfo.ProcessName == "some_process", ProcessSignal.SIGKILL, (ex)=>Console.WriteLine(ex.Message));
ProcessManager.Instance.Kill((processInfo)=>processInfo.ProcessName == "some_process");// signal SIGTERM
This software is distributed under the terms of the MIT License (MIT).
Alexander Chermyanin / LinkedIn
Contributions and bugs reports are welcome.