mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-01-17 10:45:49 +02:00
fixed GetProcessByName in mono.
This commit is contained in:
parent
5a52de7ba9
commit
bedbfc6c92
@ -2,6 +2,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Common.Model;
|
using NzbDrone.Common.Model;
|
||||||
|
|
||||||
namespace NzbDrone.Common
|
namespace NzbDrone.Common
|
||||||
@ -50,6 +51,14 @@ public ProcessInfo GetProcessById(int id)
|
|||||||
|
|
||||||
public IEnumerable<ProcessInfo> GetProcessByName(string name)
|
public IEnumerable<ProcessInfo> GetProcessByName(string name)
|
||||||
{
|
{
|
||||||
|
if (OsInfo.IsMono)
|
||||||
|
{
|
||||||
|
var mono = Process.GetProcessesByName("mono");
|
||||||
|
|
||||||
|
return mono.Where(process => process.Modules.Cast<ProcessModule>().Any(module => module.ModuleName.ToLower() == name + ".exe"))
|
||||||
|
.Select(ConvertToProcessInfo);
|
||||||
|
}
|
||||||
|
|
||||||
return Process.GetProcessesByName(name).Select(ConvertToProcessInfo).Where(p => p != null);
|
return Process.GetProcessesByName(name).Select(ConvertToProcessInfo).Where(p => p != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +100,17 @@ public void SetPriority(int processId, ProcessPriorityClass priority)
|
|||||||
process.PriorityClass = priority;
|
process.PriorityClass = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void KillAll(string processName)
|
||||||
|
{
|
||||||
|
var processToKill = GetProcessByName(processName);
|
||||||
|
|
||||||
|
foreach (var processInfo in processToKill)
|
||||||
|
{
|
||||||
|
Kill(processInfo.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static ProcessInfo ConvertToProcessInfo(Process process)
|
private static ProcessInfo ConvertToProcessInfo(Process process)
|
||||||
{
|
{
|
||||||
if (process == null || process.Id <= 0 || process.HasExited) return null;
|
if (process == null || process.Id <= 0 || process.HasExited) return null;
|
||||||
@ -104,15 +124,7 @@ private static ProcessInfo ConvertToProcessInfo(Process process)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void KillAll(string processName)
|
|
||||||
{
|
|
||||||
var processToKill = GetProcessByName(processName);
|
|
||||||
|
|
||||||
foreach (var processInfo in processToKill)
|
|
||||||
{
|
|
||||||
Kill(processInfo.Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Kill(int processId)
|
private void Kill(int processId)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user