Skip to content

Instantly share code, notes, and snippets.

@brianmed
Last active December 18, 2021 02:32
Show Gist options
  • Save brianmed/d7dfb1fc739356f4aaa2cc047c1e6fa6 to your computer and use it in GitHub Desktop.
Save brianmed/d7dfb1fc739356f4aaa2cc047c1e6fa6 to your computer and use it in GitHub Desktop.
Posix Signals in .Net 6!!
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>
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);
}
}
}
@Animadoria
Copy link

OH MY GOD YES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment