Exemplo n.º 1
0
        public void ProcessManager_Kill_By_Process_Name()
        {
            {
                var process = StartProcess();

                var uid = Syscall.GetEffectiveUserId();
                Assert.NotNull(process);
                Linux.ProcessManager.Instance.Kill("sleep", (uint)uid, ProcessSignal.SIGKILL, e => _testOutput.WriteLine(e.Message));

                Waiter.Wait(() => Linux.ProcessManager.GetProcessInfoById(process.Id) == null, TimeSpan.FromSeconds(2));
                var actual = Linux.ProcessManager.GetProcessInfoById(process.Id);
                Assert.Null(actual);
            }

            {
                var process = StartProcess();
                var name    = Syscall.GetPasswdByUserId(Syscall.GetEffectiveUserId()).pw_name;
                Assert.NotNull(process);
                Linux.ProcessManager.Instance.Kill("sleep", name, ProcessSignal.SIGKILL, e => _testOutput.WriteLine(e.Message));
                Waiter.Wait(() => Linux.ProcessManager.GetProcessInfoById(process.Id) == null, TimeSpan.FromSeconds(2));
                var actual = Linux.ProcessManager.GetProcessInfoById(process.Id);
                Assert.Null(actual);
            }

            {
                var process = StartProcess();
                Assert.NotNull(process);
                Linux.ProcessManager.Instance.Kill(_ => _.ProcessName == "sleep", ProcessSignal.SIGKILL, e => _testOutput.WriteLine(e.Message));
                Waiter.Wait(() => Linux.ProcessManager.GetProcessInfoById(process.Id) == null, TimeSpan.FromSeconds(2));
                var actual = Linux.ProcessManager.GetProcessInfoById(process.Id);
                Assert.Null(actual);
            }
        }
Exemplo n.º 2
0
        public void ProcessManager_GetProcessInfos_Should_Return_ExecutablePath_If_Allowed()
        {
            var actual = Linux.ProcessManager.GetProcessInfos();

            Assert.NotEmpty(actual);
            var uid         = Syscall.GetEffectiveUserId();
            var userProcess = actual.FirstOrDefault(_ => _.Euid == uid && _.ProcessName != "sshd");

            Assert.NotNull(userProcess);
            _testOutput.WriteLine($"{userProcess.ProcessName}:{userProcess.ProcessId}. Exe: {userProcess.ExecutablePath}. Uid: {userProcess.Euid}");
            Assert.Equal(uid, userProcess.Ruid);
            Assert.Equal(uid, userProcess.Euid);
            Assert.NotEmpty(userProcess.ExecutablePath);
        }