GLib.test_trap_fork
Description: Reference for GLib.test_trap_fork

### Function

# GLibtest_trap_fork

deprecated: Unknown since: 2.16

#### Declaration [src]

    gboolean
    g_test_trap_fork (
      guint64 usec_timeout,
      GTestTrapFlags test_trap_flags
    )

#### Description [src]

Forks the current test program to execute a test case that might not return or that might abort.

If `usec_timeout` is non-0, the forked test case is aborted and considered failing if its run time exceeds it.

The forking behavior can be configured with `GTestTrapFlags` flags.

In the following example, the test code forks, the forked child process produces some sample output and exits successfully. The forking parent process then asserts successful child program termination and validates child program outputs.

      static void
      test_fork_patterns (void)
      {
        if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
          {
            g_print ("some stdout text: somagic17
    ");
            g_printerr ("some stderr text: semagic43
    ");
            exit (0); // successful test run
          }
        g_test_trap_assert_passed ();
        g_test_trap_assert_stdout ("*somagic17*");
        g_test_trap_assert_stderr ("*semagic43*");
      }

Available since: 2.16

Deprecated since: Unknown

This function is implemented only on Unix platforms, is not always reliable due to problems inherent in fork-without-exec and doesn’t set close-on-exec flag on its file descriptors. Use func@GLib.test_trap_subprocess] instead.

#### Parameters

`usec_timeout`

  Type: `guint64`

  Timeout for the forked test in microseconds.

`test_trap_flags`

  Type: `GTestTrapFlags`

  Flags to modify forking behaviour.

#### Return value

Type: `gboolean`

True for the forked child and false for the executing parent process.