Compare commits
2 Commits
06ea991a6c
...
5eec358b68
| Author | SHA1 | Date | |
|---|---|---|---|
| 5eec358b68 | |||
| 7c1cbb44f8 |
@@ -59,6 +59,41 @@ namespace ResourceMonitorService
|
|||||||
await context.Response.WriteAsync(json);
|
await context.Response.WriteAsync(json);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.MapPost("/api/kill-process", async context =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var idStr = await new StreamReader(context.Request.Body).ReadToEndAsync();
|
||||||
|
int processId = Convert.ToInt32(idStr);
|
||||||
|
|
||||||
|
Process[] processes = Process.GetProcesses().Where(p => p.Id == processId).ToArray();
|
||||||
|
|
||||||
|
if (processes.Length > 0)
|
||||||
|
{
|
||||||
|
foreach (var process in processes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
process.Kill();
|
||||||
|
await context.Response.WriteAsync($"Process with ID {processId} has been killed.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await context.Response.WriteAsync($"Error killing process with ID {processId}: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await context.Response.WriteAsync($"No process found with ID {processId}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await context.Response.WriteAsync($"An error occurred: {ex.Message}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
_ = app.RunAsync(stoppingToken);
|
_ = app.RunAsync(stoppingToken);
|
||||||
|
|
||||||
await Task.Delay(Timeout.Infinite, stoppingToken);
|
await Task.Delay(Timeout.Infinite, stoppingToken);
|
||||||
|
|||||||
Reference in New Issue
Block a user