Last active
December 18, 2021 02:32
-
-
Save brianmed/d7dfb1fc739356f4aaa2cc047c1e6fa6 to your computer and use it in GitHub Desktop.
Posix Signals in .Net 6!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
</PropertyGroup> | |
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Runtime.InteropServices; | |
using System.Threading.Tasks; | |
namespace Joy | |
{ | |
class Program | |
{ | |
async static Task Main(string[] args) | |
{ | |
Process currentProcess = Process.GetCurrentProcess(); | |
Console.WriteLine($"Process.Id: {currentProcess.Id}"); | |
PosixSignalRegistration.Create(PosixSignal.SIGTERM, (ctx) => { | |
Console.WriteLine("Recevied SIGTERM. Exiting."); | |
Environment.Exit(0); | |
}); | |
await Task.Delay(Int32.MaxValue); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OH MY GOD YES