3 * A simple wrapper on top of fork(). This does not handle the
4 * EXEC_BACKEND case; it might be extended to do so, but it would be
5 * considerably more complex.
7 * Copyright (c) 1996-2005, PostgreSQL Global Development Group
10 * $PostgreSQL: pgsql/src/backend/postmaster/fork_process.c,v 1.4 2005/10/15 02:49:23 momjian Exp $
13 #include "postmaster/fork_process.h"
21 * Wrapper for fork(). Return values are the same as those for fork():
22 * -1 if the fork failed, 0 in the child process, and the PID of the
23 * child in the parent process.
31 struct itimerval prof_itimer;
35 * Flush stdio channels just before fork, to avoid double-output problems.
36 * Ideally we'd use fflush(NULL) here, but there are still a few non-ANSI
37 * stdio libraries out there (like SunOS 4.1.x) that coredump if we do.
38 * Presently stdout and stderr are the only stdio output channels used by
39 * the postmaster, so fflush'ing them should be sufficient.
47 * Linux's fork() resets the profiling timer in the child process. If we
48 * want to profile child processes then we need to save and restore the
49 * timer setting. This is a waste of time if not profiling, however, so
50 * only do it if commanded by specific -DLINUX_PROFILE switch.
52 getitimer(ITIMER_PROF, &prof_itimer);
56 /* Specific beos actions before backend startup */
57 beos_before_backend_startup();
61 if (result == (pid_t) -1)
65 /* Specific beos backend startup actions */
66 beos_backend_startup_failed();
71 /* fork succeeded, in child */
73 setitimer(ITIMER_PROF, &prof_itimer, NULL);
77 /* Specific beos backend startup actions */
78 beos_backend_startup();