Description
From http://java.net/jira/browse/MACOSX_PORT-638
jdk/src/solaris/native/java/lang/UNIXProcess_md.c says:
// Note that we cannot use posix_spawn
// ourselves because there's no reliable way to close all inherited
// file descriptors.
// The above is not true on mac os 10.7 and higher. See the man page for
// posix_spawnattr_setflags:
NAME
posix_spawnattr_setflags posix_spawnattr_getflags – get or set flags on a posix_spawnattr_t
SYNOPSIS
#include <spawn.h>
int
posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags);
int
posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags);
DESCRIPTION
The posix_spawnattr_setflags() function sets the flags on the attributes object referenced by attr.
The posix_spawnattr_getflags() function retrieves the flags on the attributes object referenced by attr.
The argument flags is either 0 or a logical OR of one or more of the following flags:
POSIX_SPAWN_CLOEXEC_DEFAULT Apple Extension: If this bit is set, then only file descriptors explicitly described by the file_actions
argument are available in the spawned process; all of the other file descriptors are automatically closed in
the spawned process.
In addition to POSIX_SPAWN_CLOEXEC_DEFAULT, you will need to figure out whether or not lion is running. While it might be possible to pass this flag on snow leopard and get an error (I have not tried it), it would be safer to ask the os for its version. To do this, you will need to add -framework CoreServices to the C compile command. Then, your code will look something like:
#include <CoreServices/CoreServices.h>
int32_t majorVersion,minorVersion,bugFixVersion;
Gestalt(gestaltSystemVersionMajor, &majorVersion);
Gestalt(gestaltSystemVersionMinor, &minorVersion);
Gestalt(gestaltSystemVersionBugFix, &bugFixVersion);
if ((majorVersion >= 10) && (minorVersion >= 7)) { // lion or later // use posix_spawn } else { // snow leopard or before // use fork (or figure out how to use vfork safely) }
jdk/src/solaris/native/java/lang/UNIXProcess_md.c says:
// Note that we cannot use posix_spawn
// ourselves because there's no reliable way to close all inherited
// file descriptors.
// The above is not true on mac os 10.7 and higher. See the man page for
// posix_spawnattr_setflags:
NAME
posix_spawnattr_setflags posix_spawnattr_getflags – get or set flags on a posix_spawnattr_t
SYNOPSIS
#include <spawn.h>
int
posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags);
int
posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags);
DESCRIPTION
The posix_spawnattr_setflags() function sets the flags on the attributes object referenced by attr.
The posix_spawnattr_getflags() function retrieves the flags on the attributes object referenced by attr.
The argument flags is either 0 or a logical OR of one or more of the following flags:
POSIX_SPAWN_CLOEXEC_DEFAULT Apple Extension: If this bit is set, then only file descriptors explicitly described by the file_actions
argument are available in the spawned process; all of the other file descriptors are automatically closed in
the spawned process.
In addition to POSIX_SPAWN_CLOEXEC_DEFAULT, you will need to figure out whether or not lion is running. While it might be possible to pass this flag on snow leopard and get an error (I have not tried it), it would be safer to ask the os for its version. To do this, you will need to add -framework CoreServices to the C compile command. Then, your code will look something like:
#include <CoreServices/CoreServices.h>
int32_t majorVersion,minorVersion,bugFixVersion;
Gestalt(gestaltSystemVersionMajor, &majorVersion);
Gestalt(gestaltSystemVersionMinor, &minorVersion);
Gestalt(gestaltSystemVersionBugFix, &bugFixVersion);
if ((majorVersion >= 10) && (minorVersion >= 7)) { // lion or later // use posix_spawn } else { // snow leopard or before // use fork (or figure out how to use vfork safely) }