|
|
@ -1,5 +1,4 @@
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
@ -12,10 +11,9 @@ namespace NzbDrone.Common
|
|
|
|
ProcessInfo GetCurrentProcess();
|
|
|
|
ProcessInfo GetCurrentProcess();
|
|
|
|
ProcessInfo GetProcessById(int id);
|
|
|
|
ProcessInfo GetProcessById(int id);
|
|
|
|
IEnumerable<ProcessInfo> GetProcessByName(string name);
|
|
|
|
IEnumerable<ProcessInfo> GetProcessByName(string name);
|
|
|
|
void Start(string path);
|
|
|
|
Process Start(string path);
|
|
|
|
Process Start(ProcessStartInfo startInfo);
|
|
|
|
Process Start(ProcessStartInfo startInfo);
|
|
|
|
void WaitForExit(Process process);
|
|
|
|
void WaitForExit(Process process);
|
|
|
|
void Kill(int processId);
|
|
|
|
|
|
|
|
void SetPriority(int processId, ProcessPriorityClass priority);
|
|
|
|
void SetPriority(int processId, ProcessPriorityClass priority);
|
|
|
|
void KillAll(string processName);
|
|
|
|
void KillAll(string processName);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -55,9 +53,9 @@ namespace NzbDrone.Common
|
|
|
|
return Process.GetProcessesByName(name).Select(ConvertToProcessInfo).Where(p => p != null);
|
|
|
|
return Process.GetProcessesByName(name).Select(ConvertToProcessInfo).Where(p => p != null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Start(string path)
|
|
|
|
public Process Start(string path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Process.Start(path);
|
|
|
|
return Start(new ProcessStartInfo(path));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Process Start(ProcessStartInfo startInfo)
|
|
|
|
public Process Start(ProcessStartInfo startInfo)
|
|
|
@ -69,6 +67,7 @@ namespace NzbDrone.Common
|
|
|
|
StartInfo = startInfo
|
|
|
|
StartInfo = startInfo
|
|
|
|
};
|
|
|
|
};
|
|
|
|
process.Start();
|
|
|
|
process.Start();
|
|
|
|
|
|
|
|
|
|
|
|
return process;
|
|
|
|
return process;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -78,27 +77,7 @@ namespace NzbDrone.Common
|
|
|
|
process.WaitForExit();
|
|
|
|
process.WaitForExit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Kill(int processId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (processId == 0 || Process.GetProcesses().All(p => p.Id != processId))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Warn("Cannot find process with id: {0}", processId);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var process = Process.GetProcessById(processId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (process.HasExited)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Info("[{0}]: Killing process", process.Id);
|
|
|
|
|
|
|
|
process.Kill();
|
|
|
|
|
|
|
|
Logger.Info("[{0}]: Waiting for exit", process.Id);
|
|
|
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
|
|
|
Logger.Info("[{0}]: Process terminated successfully", process.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void SetPriority(int processId, ProcessPriorityClass priority)
|
|
|
|
public void SetPriority(int processId, ProcessPriorityClass priority)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -134,5 +113,27 @@ namespace NzbDrone.Common
|
|
|
|
Kill(processInfo.Id);
|
|
|
|
Kill(processInfo.Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Kill(int processId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (processId == 0 || Process.GetProcesses().All(p => p.Id != processId))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Warn("Cannot find process with id: {0}", processId);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var process = Process.GetProcessById(processId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (process.HasExited)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Info("[{0}]: Killing process", process.Id);
|
|
|
|
|
|
|
|
process.Kill();
|
|
|
|
|
|
|
|
Logger.Info("[{0}]: Waiting for exit", process.Id);
|
|
|
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
|
|
|
Logger.Info("[{0}]: Process terminated successfully", process.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|