Mono Class Library: Mono.Unix.Native.Stdlib Overview | Members

Mono.Unix.Native.Stdlib.exit Method

Terminates the process that calls the function with the exit status status. [Edit]

public static void exit (int status)

Parameters

status
The low-order eight bits of status are generally made available to a parent process. [Edit]

Remarks

The exit function terminates a process.

Before termination, exit() performs the following functions in the order listed:

  1. Call the functions registered with the Stdlib.atexit(3) function, in the reverse order of their registration.
  2. Flush all open output streams
  3. Close all open streams
  4. Unlink all files created with the Stdlib.tmpfile(3) function.

The low-order eight bits of the status argument is made available to a parent process which has called a Syscall.wait(2)-family function.

The C Standard (ISO/IEC 9899:1999 ("ISO C99")) defines the values 0, Stdlib.EXIT_SUCCESS, and Stdlib.EXIT_FAILURE as possible values of status. Cooperating processes may use other values; in a program which might be called by a mail transfer agent, the values described in sysexits(3) may be used to provide more information to the parent process.

Note that exit() does nothing to prevent bottomless recursion should a function registered using Stdlib.atexit(3) itself call exit(). Such functions must call Stdlib._Exit() instead (although this has other effects as well which may not be desired).

This function never returns.

C# Example
using System;
using Mono.Unix.Native;
using System.Runtime.InteropServices;

class Test
{
	public void SignalCatcher(int v)
	{
		// sleep signal caught.
		Console.WriteLine("Signal received: " + v);
		// this line will not be printed because process exits...
		Console.WriteLine("Exiting with: " + Stdlib.exit(9));
	}		
	
	public static void Main(string[] args)
	{
		Test t = new Test();
		Console.Write("waiting for event...");
		string x = Console.ReadLine();
	}
	
	public Test()
	{
		// create a signal handler delegate for sleep signals
		Console.WriteLine("signal result: " + 
			Syscall.signal(Signum.SIGALRM, 
				new SignalHandler (SignalCatcher)));
		// send a sleep signal
		Syscall.alarm(3);
	}
}
[Edit]

Requirements

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