private void TJ1() { //if (KProcessHacker.Instance != null) //{ // try // { // using (ProcessHandle phandle = new ProcessHandle(_pid, Program.MinProcessQueryRights)) // { // JobObjectHandle jhandle = phandle.GetJobObject(JobObjectAccess.Query | JobObjectAccess.Terminate); // // Make sure we're not terminating more than one process // if (jhandle.ProcessIdList.Length == 1) // { // jhandle.Terminate(); // } // } // } // catch // { } //} using (JobObjectHandle jhandle = JobObjectHandle.Create(JobObjectAccess.AssignProcess | JobObjectAccess.Terminate)) { using (ProcessHandle phandle = new ProcessHandle(_pid, ProcessAccess.SetQuota | ProcessAccess.Terminate)) { phandle.AssignToJobObject(jhandle); } jhandle.Terminate(); } }
public static void Main(string[] args) { string filepath = Path.Combine(typeof(TestProgramMemoryUsage.Program).Assembly.Location); var process1 = Process.Start(filepath); var process2 = Process.Start(filepath); var security = new JobObjectSecurity(true); security.AddAccessRule(new NTAccount("Everyone"), JobObjectAccessRights.AllAccess, AccessControlType.Allow); using (var job = JobObjectHandle.Create(security, "Foobar")) { var extendedLimitInformation = new ExtendedLimitInformation { KillOnJobClose = true, JobMemoryLimit = 3 * 1024 * 1024 * 1024UL, ProcessMemoryLimit = 100 * 1024 * 1024, }; job.SetInformation(extendedLimitInformation); job.AssignProcess(process1); using (var job2 = JobObjectHandle.Open("Foobar")) { job2.AssignProcess(process2); var extendedLimitInformation2 = job2.GetInformation <ExtendedLimitInformation>(); var basicAccountingInformation = job2.GetInformation <BasicAndIoAccountingInformation>(); var basicUiRestrictions = job2.GetInformation <BasicUiRestrictions>(); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(intercept: true); } }
public void GivenJobObjectWithoutMemoryLimit_ThenOutOfMemoryIsNotThrown() { Process process = Process.Start(typeof(TestProgramMemoryUsage.Program).Assembly.Location); using (var job = JobObjectHandle.Create()) { job.SetInformation(new ExtendedLimitInformation { }); job.AssignProcess(process); } process.WaitForExit(); Assert.Equal(0, process.ExitCode); }
public void GivenJobWithKillOnJobClose_WhenDisposingJob_ThenProcessIsStopped() { Process process = Process.Start(typeof(Program).Assembly.Location); using (var job = JobObjectHandle.Create()) { job.SetInformation(new ExtendedLimitInformation { KillOnJobClose = true, }); job.AssignProcess(process); } Assert.True(process.HasExited); Assert.Equal(0, process.ExitCode); }
private void TJ1() { if (KProcessHacker.Instance != null) { try { using (var phandle = new ProcessHandle(_pid, Program.MinProcessQueryRights)) { var jhandle = phandle.GetJobObject(JobObjectAccess.Query | JobObjectAccess.Terminate); if (jhandle != null) { // Make sure we're not terminating more than one process if (jhandle.GetProcessIdList().Length == 1) { jhandle.Terminate(); return; } } } } catch { } } using (var jhandle = JobObjectHandle.Create(JobObjectAccess.AssignProcess | JobObjectAccess.Terminate)) { using (ProcessHandle phandle = new ProcessHandle(_pid, ProcessAccess.SetQuota | ProcessAccess.Terminate)) { phandle.AssignToJobObject(jhandle); } jhandle.Terminate(); } }
public IJobObject Create(string name = null) { var handle = JobObjectHandle.Create(name); return(new JobObject(handle)); }
public IJobObject Create(JobObjectSecurity jobObjectSecurity, string name = null) { var handle = JobObjectHandle.Create(jobObjectSecurity, name); return(new JobObject(handle)); }