Description
Description
I am writing a console application in F# using .NET 7. I am wanting to intercept and prevent console exit signals, such as PosixSignal.SIGTSTP
and PosixSignal.SIGINT
. These enums are defined here. To ignore them, I create and register a handler using PosixSignalRegistration.Create
and then write true
to the Cancel
property inside the handler. This should cancel the signal, to my understanding, as it does for PosixSignal.SIGINT
. However, that doesn't seem to be the case for PosixSignal.SIGTSTP
.
Reproduction Steps
These steps were executed on Ubuntu 20 running in WSL2 on Windows 11.
-
Save the following code into an F# script named
posix.fsx
.// posix.fsx open System open System.Runtime.InteropServices PosixSignalRegistration.Create(PosixSignal.SIGINT, fun context -> printfn "Prevented Posix SIGINT" context.Cancel <- true) |> ignore if System.OperatingSystem.IsLinux() then printfn "System is Linux" PosixSignalRegistration.Create(PosixSignal.SIGTSTP, fun context -> printfn "Prevented Posix SIGTSTP" context.Cancel <- true) |> ignore let mutable cont = true while cont do let key = Console.ReadKey(intercept = true) let keyChar = key.KeyChar let keyModifiers = key.Modifiers printfn "key: %A, modifiers: %A" keyChar keyModifiers if keyChar = 'q' then cont <- false
-
Run the script with
dotnet fsi posix.fsx
-
Type any character except
'q'
. The key information will be printed out. -
Enter
Ctrl + C
and note that"Prevented Posix SIGINT"
is printed out to the screen but that the process is still running, which can be verified by entering in other characters (again, besides'q'
). -
Enter
Ctrl + Z
and note that:[3]+ Stopped dotnet fsi posix.fsx
is printed to the screen- The process is stopped, but then
"Prevented Posix SIGTSTP"
is printed out afterwards, after the new prompt is shown. - However, the process seems to be restarted or still going, as it will respond to a key entry but usually only for one, and the process will end when
Enter
is entered. This behavior is a little inconsistent.
Expected behavior
When Ctrl + Z
is entered, "Prevented Posix SIGTSTP"
should be printed to the console without the program being stopped.
Actual behavior
$ dotnet fsi posix.fsx
System is Linux
key: 'a', modifiers: 0
key: '\013', modifiers: 0
Prevented Posix SIGINT
key: 'a', modifiers: 0
[2]+ Stopped dotnet fsi posix.fsx
$ Prevented Posix SIGTSTP
key: 'a', modifiers: 0
$
Regression?
Not sure.
Known Workarounds
None that I know of.
Configuration
$ dotnet --version
7.0.100
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal
The architecture is x64.
Other information
No response
Metadata
Metadata
Assignees
Type
Projects
Status