[Mono-list] how to receive console event signal in mono?

mike roome arhra@arslinux.com
Thu, 29 Jul 2004 05:02:49 -0400 (EDT)


[oops, forgot to cc this to the list]

Sam Jost wrote:

>I'd like to know how I would receive a console event signal in a console
>program written in mono (running on linux)
>
>On windows I would use interop and kernel32 "SetConsoleCtrlHandler" function
>to capture a ctrl+break, but somehow I don't except this to work with linux.
>
>How would one capture signals with a mono console program in linux?
>

Mono.Posix has wrappers for the POSIX signal-handling functions (in
particular, Mono.Posix.Syscall.signal() is the method you need, i
believe). I don't think there are any docs available for them (at least,
there's nothing on Mono.Posix in my local copy of Monodoc), but afaict,
they're just straight p/invoke wrappers around the native functions, so
just check the relevant man pages (man 2 signal and man 7 signal).

(actually... looking at the source, there's a Signals enum, which is
marked with a [Map] attribute, which the comments say needs to be run
through a c helper function to map the enum values to the correct
underlying value used by the system, BUT, Syscall.signal() takes a raw int
for the signum... so i have no idea if it will work portably at the
moment...)

-- 
Mike Roome