title: How to shutdown computer from a .NET Core application running on Linux
body: <p>I have a .net core 2.0 program running on Linux (Ubuntu Server 16.04 LTS). </p>
  
  <p>I'm trying to shutdown the computer by invoking a process with the following command: <code>sudo shutdown -h now</code>, though when the program is running in the background as daemon service, the shutdown process does not work. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>var process = new Process
  {
      StartInfo =
      {
          CreateNoWindow = true,
          RedirectStandardError = true,
          RedirectStandardInput = true,
          RedirectStandardOutput = true,
          UseShellExecute = false,
          FileName = Environment.GetEnvironmentVariable("SHELL"),
          Arguments = "-s"
      },
      EnableRaisingEvents = true
  };
  
  if (process.Start())
  {
      process.BeginErrorReadLine();
      process.BeginOutputReadLine();
      process.StandardInput.WriteLine("sudo shutdown -h now");
  }
  </code></pre>
  
  <p>My assumption is that the service runs as a separate session so it doesn't have any control. How can I get the application to shutdown the computer when it is running as a Linux daemon?</p>