Repository navigation
Closed
Labels
Milestone
Description
Code:
using System;
using System.IO;
namespace HelloMvc
{
public class Program
{
public static void Main(string[] args)
{
System.Console.CancelKeyPress += (s,e) => System.Console.WriteLine("BBB");
Console.ReadLine();
}
}
}
project.json:
{
"version": "1.0.1-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies" : {
"NETStandard.Library": "1.0.0-*"
},
"frameworks": {
"dnxcore50": { }
}
}
Steps:
- Compile
- Run
- Press Ctrl+C
Coreclr output:
<Empty>
Mono output:
BBB
Environment:
> uname -a
Linux pkrymets 3.19.0-31-generic dotnet/runtime#13856-Ubuntu SMP Wed Oct 7 15:04:02 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
> cat /usr/local/share/dotnet/cli/.version
ecda2a810615dda9f280fd8a87d23be2e2fcae45
1.0.0-dev-1452359345
Packages:
Package references:
Microsoft.NETCore.Platforms 1.0.1-rc2-23712
Microsoft.NETCore.Runtime 1.0.1-rc2-23712
Microsoft.NETCore.Runtime.CoreCLR 1.0.1-rc2-23712
Microsoft.NETCore.Runtime.Native 1.0.1-rc2-23712
Microsoft.NETCore.Targets 1.0.1-rc2-23712
Microsoft.NETCore.Targets.DNXCore 5.0.0-rc2-23712
Microsoft.NETCore.Windows.ApiSets 1.0.1-rc2-23712
Microsoft.Win32.Primitives 4.0.1-rc2-23712
* NETStandard.Library 1.0.0-rc2-23712
NETStandard.Platform 1.0.0-rc2-23712
System.AppContext 4.0.1-rc2-23712
System.Collections 4.0.11-rc2-23712
System.Collections.Concurrent 4.0.11-rc2-23712
System.Console 4.0.0-rc2-23712
System.Diagnostics.Debug 4.0.11-rc2-23712
System.Diagnostics.Process 4.1.0-rc2-23712
System.Diagnostics.Tools 4.0.1-rc2-23712
System.Diagnostics.Tracing 4.0.21-rc2-23712
System.Globalization 4.0.11-rc2-23712
System.Globalization.Calendars 4.0.1-rc2-23712
System.IO 4.1.0-rc2-23712
System.IO.FileSystem 4.0.1-rc2-23712
System.IO.FileSystem.Primitives 4.0.1-rc2-23712
System.Linq 4.0.1-rc2-23712
System.Net.Primitives 4.0.11-rc2-23712
System.Net.Sockets 4.1.0-rc2-23712
System.Private.Uri 4.0.1-rc2-23712
System.Reflection 4.1.0-rc2-23712
System.Reflection.Extensions 4.0.1-rc2-23712
System.Reflection.Primitives 4.0.1-rc2-23712
System.Reflection.TypeExtensions 4.1.0-rc2-23712
System.Resources.ResourceManager 4.0.0
System.Runtime 4.0.21-rc2-23712
System.Runtime.Extensions 4.0.11-rc2-23712
System.Runtime.Handles 4.0.1-rc2-23712
System.Runtime.InteropServices 4.0.21-rc2-23712
System.Runtime.InteropServices.RuntimeInformation 4.0.0-rc2-23712
System.Runtime.Numerics 4.0.1-rc2-23712
System.Text.Encoding 4.0.11-rc2-23712
System.Text.Encoding.Extensions 4.0.11-rc2-23712
System.Text.RegularExpressions 4.0.11-rc2-23712
System.Threading 4.0.11-rc2-23712
System.Threading.Tasks 4.0.11-rc2-23712
System.Threading.Timer 4.0.1-rc2-23712
Activity
[-]CancelKeyPress not workin[/-][+]CancelKeyPress not firing on coreclr on ubuntu[/+]stephentoub commentedon Jan 12, 2016
What build are you using? Can you share a minimal repro?
pakrym commentedon Jan 12, 2016
Updated issue with more information.
stephentoub commentedon Jan 12, 2016
I'm on Ubuntu 14.04. I just tried your repro building coreclr/corefx from the latest sources and using corerun. I also tried downloading dotnet-cli from the tarball at https://github.com/dotnet/cli and using dotnet build. In both cases, it produced the expected output, printing out BBB and then exiting.
@pallavit, are you able to repro this?
@pakrym, just to make sure you're not accidentally ctrl-c'ing before you've actually gotten to the registration, can you add a Console.WriteLine after the CancelKeyPress registration so you know that it's actually completed?
pakrym commentedon Jan 12, 2016
Added
WriteLinebefore read line, observe the same behavior.pakrym commentedon Jan 12, 2016
Updated to latest 1.0.0-dev-1452620519 dotnet, didn't help
stephentoub commentedon Jan 12, 2016
Spoke offline with @pakrym... turns out when building and then executing with
dotnet, he does see the handler execute correctly. It's just when usingdotnet runthat the handler doesn't get invoked.In trying it out locally, it looks like this is an issue specific to how
dotnet runis designed/implemented, not with corefx or coreclr. The SIGINT signal from the ctrl-c press is getting sent to thedotnetprocess and killing it.cc: @piotrpMSFT
stephentoub commentedon Jan 12, 2016
Moving to https://github.com/dotnet/cli/issues/812.
davidfowl commentedon Jan 12, 2016
Forget
dotnet runfor a minute, is there a way to handle SIGTERM in .NET Core? Or does that require pinvoking?MaximRouiller commentedon Jan 13, 2016
SIGTERM would be handled by libuv right? If I recall, libuv does not flow back that event back. Unless you have a custom version of libuv, that might be it.
TheRealPiotrP commentedon Jan 14, 2016
@davidfowl it looks like we can receive SIGTERM via System.Console.CancelKeyPress. When we receive it we should pass it on from dotnet --> dotnet-run --> the app.
@stephentoub is there an API to send Ctrl+C to a spawned process?
stephentoub commentedon Jan 14, 2016
Not unless some other code is registering for SIGTERM and sending another signal in its place. CancelKeyPress is for ConsoleSpecialKey.ControlC and ConsoleSpecialKey.ControlBreak, which are SIGINT and SIGQUIT, respectively. SIGTERM does not currently trigger a CancelKeyPress event.
Not exposed in the framework. On Unix it can be achieved via a P/Invoke to
kill, and on Windows via a P/Invoke to GenerateConsoleCtrlEvent I believe. There's an open issue requesting such a feature be added (https://github.com/dotnet/corefx/issues/1838), but there's also no reason it needs to be in corefx itself and could easily be done as a 3rd-party library.