diff --git a/CoreAgent.API/Configurations/netcommand.json b/CoreAgent.API/Configurations/netcommand.json index db153af..856bb26 100644 --- a/CoreAgent.API/Configurations/netcommand.json +++ b/CoreAgent.API/Configurations/netcommand.json @@ -35,12 +35,12 @@ }, { "type": 0, - "template": "pkill tcpdump", + "template": "tcpdump", "timeout": 5000, "isEnabled": true, "needReturnResult": false, "needBackgroundExecution": false, - "canBeKilled": false, + "canBeKilled": true, "hasParameters": false }, { diff --git a/CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs b/CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs index 364b9ac..549fa23 100644 --- a/CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs +++ b/CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs @@ -192,7 +192,7 @@ public class CellularNetworkService : ICellularNetworkService { if (command.CanBeKilled) { - await KillProcessAsync(command.Template, command.Timeout); + return await KillProcessAsync(command.Template, command.Timeout); } var result = await _commandExecutor.ExecuteCommandAsync(command.Template, new CancellationTokenSource(),command.Timeout); @@ -205,11 +205,12 @@ public class CellularNetworkService : ICellularNetworkService } } - private async Task KillProcessAsync(string template,int Timeout) + private async Task KillProcessAsync(string template,int Timeout) { string killCmd = $"ps -ef | grep {template} | grep -v grep | awk '{{print $2}}' | xargs kill -9"; - await _commandExecutor.ExecuteCommandAsync(killCmd, new CancellationTokenSource()); + var result = await _commandExecutor.ExecuteCommandAsync(killCmd, new CancellationTokenSource()); _logger.LogInformation("已终止进程: {Template}", template); + return result.IsSuccess; } private async Task EnableNetworkInterfaceAsync(NetworkConfiguration networkConfig)