5659 5660 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); 5661 if (fd != -1) { 5662 struct stat buf; 5663 ::close(fd); 5664 while (::stat(filename, &buf) == 0) { 5665 (void)::poll(NULL, 0, 100); 5666 } 5667 } else { 5668 jio_fprintf(stderr, 5669 "Could not open pause file '%s', continuing immediately.\n", filename); 5670 } 5671 } 5672 5673 extern char** environ; 5674 5675 // Run the specified command in a separate process. Return its exit value, 5676 // or -1 on failure (e.g. can't fork a new process). 5677 // Unlike system(), this function can be called from signal handler. It 5678 // doesn't block SIGINT et al. 5679 int os::fork_and_exec(char* cmd) { 5680 const char * argv[4] = {"sh", "-c", cmd, NULL}; 5681 5682 pid_t pid = fork(); 5683 5684 if (pid < 0) { 5685 // fork failed 5686 return -1; 5687 5688 } else if (pid == 0) { 5689 // child process 5690 5691 execve("/bin/sh", (char* const*)argv, environ); 5692 5693 // execve failed 5694 _exit(-1); 5695 5696 } else { 5697 // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't 5698 // care about the actual exit code, for now. 5699 5700 int status; 5701 5702 // Wait for the child process to exit. This returns immediately if | 5659 5660 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); 5661 if (fd != -1) { 5662 struct stat buf; 5663 ::close(fd); 5664 while (::stat(filename, &buf) == 0) { 5665 (void)::poll(NULL, 0, 100); 5666 } 5667 } else { 5668 jio_fprintf(stderr, 5669 "Could not open pause file '%s', continuing immediately.\n", filename); 5670 } 5671 } 5672 5673 extern char** environ; 5674 5675 // Run the specified command in a separate process. Return its exit value, 5676 // or -1 on failure (e.g. can't fork a new process). 5677 // Unlike system(), this function can be called from signal handler. It 5678 // doesn't block SIGINT et al. 5679 int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { 5680 const char * argv[4] = {"sh", "-c", cmd, NULL}; 5681 5682 pid_t pid ; 5683 5684 if (use_vfork_if_available) { 5685 pid = vfork(); 5686 } else { 5687 pid = fork(); 5688 } 5689 5690 if (pid < 0) { 5691 // fork failed 5692 return -1; 5693 5694 } else if (pid == 0) { 5695 // child process 5696 5697 execve("/bin/sh", (char* const*)argv, environ); 5698 5699 // execve failed 5700 _exit(-1); 5701 5702 } else { 5703 // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't 5704 // care about the actual exit code, for now. 5705 5706 int status; 5707 5708 // Wait for the child process to exit. This returns immediately if |