Skip to content

Commit f04a527

Browse files
authored
Clarify default signal handling changes in .NET 10 (#48219)
1 parent de9c03a commit f04a527

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

docs/core/compatibility/core-libraries/10.0/sigterm-signal-handler.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
---
2-
title: "Breaking change: .NET runtime no longer provides default SIGTERM signal handler"
3-
description: "Learn about the breaking change in .NET 10 where the runtime no longer provides a default SIGTERM signal handler."
2+
title: "Breaking change: .NET runtime no longer provides default termination signal handler"
3+
description: "Learn about the breaking change in .NET 10 where the runtime no longer provides a default termination signal handler."
44
ms.date: 06/06/2025
55
ai-usage: ai-assisted
66
ms.custom: https://github.com/dotnet/docs/issues/46226
77
---
8-
# .NET runtime no longer provides default SIGTERM signal handler
8+
# .NET runtime no longer provides default termination signal handlers
99

10-
On Unix systems, the .NET runtime no longer provides a default SIGTERM signal handler. On Windows, the .NET runtime no longer provides default handlers for the [`CTRL_CLOSE_EVENT` and `CTRL_SHUTDOWN_EVENT` signals](/windows/console/handlerroutine), which are equivalents of Unix `SIGTERM` signal.
10+
On Unix systems, the .NET runtime no longer provides a default SIGTERM signal handler. On Windows, the .NET runtime no longer provides default handlers for the [`CTRL_SHUTDOWN_EVENT` and `CTRL_CLOSE_EVENT` signals](/windows/console/handlerroutine), which are equivalents of Unix `SIGTERM` and `SIGHUP` signals.
1111

12-
This change reverts the SIGTERM signal handling behavior to what it used to be in .NET Framework and classic Mono runtime.
12+
This change reverts the termination signal handling behavior to what it used to be in .NET Framework and classic Mono runtime.
1313

1414
## Version introduced
1515

1616
.NET 10 Preview 5
1717

1818
## Previous behavior
1919

20-
Previously, a SIGTERM signal handler registered by the .NET runtime by default triggered graceful application exit. <xref:System.AppDomain.ProcessExit?displayProperty=nameWithType> and <xref:System.Runtime.Loader.AssemblyLoadContext.Unloading?displayProperty=nameWithType> events were raised before the application exited.
20+
Previously, termination signal handlers registered by the .NET runtime by default triggered graceful application exit. <xref:System.AppDomain.ProcessExit?displayProperty=nameWithType> and <xref:System.Runtime.Loader.AssemblyLoadContext.Unloading?displayProperty=nameWithType> events were raised before the application exited.
2121

2222
## New behavior
2323

24-
Starting in .NET 10, the .NET runtime does not override SIGTERM signal handling provided by the operating system. The typical default SIGTERM signal handler provided by the operating system terminates the application immediately. <xref:System.AppDomain.ProcessExit?displayProperty=nameWithType> and <xref:System.Runtime.Loader.AssemblyLoadContext.Unloading?displayProperty=nameWithType> events aren't raised.
24+
Starting in .NET 10, the .NET runtime does not override termination signal handling provided by the operating system. The typical default termination signal handler provided by the operating system terminates the application immediately. <xref:System.AppDomain.ProcessExit?displayProperty=nameWithType> and <xref:System.Runtime.Loader.AssemblyLoadContext.Unloading?displayProperty=nameWithType> events aren't raised.
2525

2626
## Type of breaking change
2727

2828
This is a [behavioral change](../../categories.md#behavioral-change).
2929

3030
## Reason for change
3131

32-
The SIGTERM signal handler registered by the .NET runtime by default was both insufficient for some app models (for example, console and containerized applications) and incompatible with other app models (for example, Windows services). It's better to leave it to higher-level libraries or application code to register signal handlers appropriate for the given app model.
32+
The termination signal handlers registered by the .NET runtime by default were both insufficient for some app models (for example, console and containerized applications) and incompatible with other app models (for example, Windows services). It's better to leave it to higher-level libraries or application code to register signal handlers appropriate for the given app model.
3333

3434
## Recommended action
3535

3636
- No action is necessary for typical ASP.NET applications or applications that use higher-level APIs such as <xref:Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.UseConsoleLifetime*?displayProperty=nameWithType> to handle app-model specific concerns. These higher-level APIs register handlers for SIGTERM and other signals as appropriate.
3737

38-
- If you want to handle SIGTERM signal without taking a dependency on higher-level libraries, you can replicate the previous behavior by creating a SIGTERM signal handler in your `Main` method using the <xref:System.Runtime.InteropServices.PosixSignalRegistration.Create%2A?displayProperty=nameWithType> API:
38+
- If you want to handle termination signals without taking a dependency on higher-level libraries, you can replicate the previous behavior by creating termination signal handlers in your `Main` method using the <xref:System.Runtime.InteropServices.PosixSignalRegistration.Create%2A?displayProperty=nameWithType> API:
3939

4040
```csharp
4141
static void Main()
@@ -45,6 +45,12 @@ static void Main()
4545
PosixSignal.SIGTERM,
4646
(_) => Environment.Exit(0));
4747

48+
// Replicates the previous behavior on Windows
49+
using var sigHupSignalRegistration =
50+
PosixSignalRegistration.Create(
51+
PosixSignal.SIGHUP,
52+
(_) => Environment.Exit(0));
53+
4854
// Your application code here
4955
}
5056
```

0 commit comments

Comments
 (0)