< prev index next >

src/hotspot/os/bsd/os_bsd.cpp

Print this page




3778       (void)::poll(NULL, 0, 100);
3779     }
3780   } else {
3781     jio_fprintf(stderr,
3782                 "Could not open pause file '%s', continuing immediately.\n", filename);
3783   }
3784 }
3785 
3786 // Darwin has no "environ" in a dynamic library.
3787 #ifdef __APPLE__
3788   #include <crt_externs.h>
3789   #define environ (*_NSGetEnviron())
3790 #else
3791 extern char** environ;
3792 #endif
3793 
3794 // Run the specified command in a separate process. Return its exit value,
3795 // or -1 on failure (e.g. can't fork a new process).
3796 // Unlike system(), this function can be called from signal handler. It
3797 // doesn't block SIGINT et al.
3798 int os::fork_and_exec(char* cmd) {
3799   const char * argv[4] = {"sh", "-c", cmd, NULL};
3800 
3801   // fork() in BsdThreads/NPTL is not async-safe. It needs to run
3802   // pthread_atfork handlers and reset pthread library. All we need is a
3803   // separate process to execve. Make a direct syscall to fork process.
3804   // On IA64 there's no fork syscall, we have to use fork() and hope for
3805   // the best...
3806   pid_t pid = fork();
3807 
3808   if (pid < 0) {
3809     // fork failed
3810     return -1;
3811 
3812   } else if (pid == 0) {
3813     // child process
3814 
3815     // execve() in BsdThreads will call pthread_kill_other_threads_np()
3816     // first to kill every thread on the thread list. Because this list is
3817     // not reset by fork() (see notes above), execve() will instead kill
3818     // every thread in the parent process. We know this is the only thread




3778       (void)::poll(NULL, 0, 100);
3779     }
3780   } else {
3781     jio_fprintf(stderr,
3782                 "Could not open pause file '%s', continuing immediately.\n", filename);
3783   }
3784 }
3785 
3786 // Darwin has no "environ" in a dynamic library.
3787 #ifdef __APPLE__
3788   #include <crt_externs.h>
3789   #define environ (*_NSGetEnviron())
3790 #else
3791 extern char** environ;
3792 #endif
3793 
3794 // Run the specified command in a separate process. Return its exit value,
3795 // or -1 on failure (e.g. can't fork a new process).
3796 // Unlike system(), this function can be called from signal handler. It
3797 // doesn't block SIGINT et al.
3798 int os::fork_and_exec(char* cmd, bool use_vfork_if_available) {
3799   const char * argv[4] = {"sh", "-c", cmd, NULL};
3800 
3801   // fork() in BsdThreads/NPTL is not async-safe. It needs to run
3802   // pthread_atfork handlers and reset pthread library. All we need is a
3803   // separate process to execve. Make a direct syscall to fork process.
3804   // On IA64 there's no fork syscall, we have to use fork() and hope for
3805   // the best...
3806   pid_t pid = fork();
3807 
3808   if (pid < 0) {
3809     // fork failed
3810     return -1;
3811 
3812   } else if (pid == 0) {
3813     // child process
3814 
3815     // execve() in BsdThreads will call pthread_kill_other_threads_np()
3816     // first to kill every thread on the thread list. Because this list is
3817     // not reset by fork() (see notes above), execve() will instead kill
3818     // every thread in the parent process. We know this is the only thread


< prev index next >