Mono Class Library: Mono.Unix Namespace

Mono.Unix.UnixSignal Class

Represents the number of times a Unix signal has been emitted.

See Also: UnixSignal Members

System.Threading.WaitHandle
     Mono.Unix.UnixSignal

public class UnixSignal : System.Threading.WaitHandle

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

Unix signals are used (generally) for two things:

The key nature about signals is that they are asynchronous. In a single threaded program, when a signal occurs the executing thread is "hijacked" (no matter what it was previously doing) in order to execute a (optionally registered) signal handler, and then the thread resumes what it was previously doing (if possible; the signal handler may abort the process as part of its execution).

In a multi-threaded program, a thread is selected at random among the threads that can handle the signal, and that thread is hijacked to run the signal handler before continuing (while the other threads continue to execute in ignorance that a signal is occuring).

Tradtionally, Mono.Unix.Native.Stdlib.signal is used to register a signal handler for a signal, and the registered handler is invoked when the signal is generated. However, due to the "hijacking" nature of the signal handling process, what the signal handler could do is severely restricted: it must not invoke non-reentrant library functions, and can only modify global data and execute a limited set of system calls such as Mono.Unix.Native.Syscall.read and Mono.Unix.Native.Syscall.write.

Managed code throws an additional wrench in the works, as the platform invocation mechanism is neither reentrant nor signal safe. Consequently, managed code can not be safely and reliably used as a signal handler (as would traditionally be done with signal(2)), thus the Mono.Unix.UnixSignal type.

A Mono.Unix.UnixSignal instance represents the number of times that a Unix signal has been emitted. That's all. UnixSignal instances support:

In order to operate, this class uses an internal unmanaged signal handler to represent the count information. Consequently, the count will only be updated as long as no other mechanism is used to change the registered signal handler, such as Mono.Unix.Native.Stdlib.signal or Mono.Unix.Native.Stdlib.SetSignalAction. If you use Mono.Unix.Native.Stdlib.signal or Mono.Unix.Native.Stdlib.SetSignalAction for the same signal as a created UnixSignal instance, the UnixSignal instance will stop operating as documented. Don't Do That (TM).

There is currently a limit of 64 concurrent UnixSignal instances within a process.

Requirements

Namespace: Mono.Unix
Assembly: Mono.Posix (in Mono.Posix.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0