从C#杀死远程Linux进程

时间:2020-02-11 10:43:39

标签: c# .net linux kill-process

我想知道我可以通过哪种方式从C#中杀死一个远程Linux进程 我尝试使用pskill,但无法正常工作..任何人都可以帮助我

string processName = "/bin/bash";
                    ProcessStartInfo pInfo = new ProcessStartInfo()
                    {
                        Arguments = $" -t  {RemoteMachineName} -u {username} -p {password} {processName}", // also kill all the child processes
                        CreateNoWindow = false,
                        RedirectStandardError = false,
                        RedirectStandardInput = false,
                        RedirectStandardOutput = false,
                        UseShellExecute = false,
                        FileName = ConfigurationManager.AppSettings["PsKillExecutablePath"]
                    };

                    var p = Process.Start(pInfo);
                    // wait for the process to exit 
                    p.WaitForExit(1000 * 60); // Wait for 60 seconds
                    if (p.ExitCode != 0)
                    {
                        logger.Error("Unable to kill the process on the remote machine ... ");
                    }
                    else
                    {
                        logger.Info("Sucessfully Killed remote process ... ");
                    }

0 个答案:

没有答案