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-2008, PostgreSQL Global Development Group
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
);
58 /* fork succeeded, in child */
60 setitimer(ITIMER_PROF
, &prof_itimer
, NULL
);