1 using Microsoft.Extensions.Logging;
3 using Mono.Unix.Native;
9 using System.Threading.Tasks;
25 readonly ILogger<PosixProcessFeatures>
logger;
34 this.ioManager = ioManager ??
throw new ArgumentNullException(nameof(ioManager));
35 this.logger = logger ??
throw new ArgumentNullException(nameof(logger));
43 var result = Syscall.kill(process.Id, Signum.SIGCONT);
45 throw new UnixIOException(result);
46 logger.LogTrace(
"Resumed PID {0}", process.Id);
50 logger.LogError(e,
"Failed to resume PID {0}!", process.Id);
60 var result = Syscall.kill(process.Id, Signum.SIGSTOP);
62 throw new UnixIOException(result);
63 logger.LogTrace(
"Resumed PID {0}", process.Id);
67 logger.LogError(e,
"Failed to suspend PID {0}!", process.Id);
73 public async Task<string>
GetExecutingUsername(global::System.Diagnostics.Process process, CancellationToken cancellationToken)
76 throw new ArgumentNullException(nameof(process));
82 var statusFile = ioManager.ConcatPath(
"/proc", pid.ToString(CultureInfo.InvariantCulture),
"status");
83 var statusBytes = await ioManager.ReadAllBytes(statusFile, cancellationToken).ConfigureAwait(
false);
84 var statusText = Encoding.UTF8.GetString(statusBytes);
85 var splits = statusText.Split(
'\n', StringSplitOptions.RemoveEmptyEntries);
86 var entry = splits.FirstOrDefault(x => x.Trim().StartsWith(
"Uid:", StringComparison.Ordinal));
92 .Split(
' ', StringSplitOptions.RemoveEmptyEntries)
93 .FirstOrDefault(x => !String.IsNullOrWhiteSpace(x))
readonly IIOManager ioManager
The IIOManager for the PosixProcessFeatures.
Use server authentication
readonly ILogger< PosixProcessFeatures > logger
The ILogger<TCategoryName> for the PosixProcessFeatures.
void SuspendProcess(global::System.Diagnostics.Process process)
Suspend a given Process.
PosixProcessFeatures(IIOManager ioManager, ILogger< PosixProcessFeatures > logger)
Initializes a new instance of the PosixProcessFeatures .
async Task< string > GetExecutingUsername(global::System.Diagnostics.Process process, CancellationToken cancellationToken)
Get the name of the user executing a given process .
Abstraction for suspending and resuming processes.
Interface for using filesystems
void ResumeProcess(global::System.Diagnostics.Process process)
Resume a given suspended Process.