Project

General

Profile

Feature #2619 ยป 0001-Add-method-Process.fork_supported-for-checking-wheth.patch

hongli (Hongli Lai), 01/21/2010 12:30 AM

View differences:

process.c
632 632
#if defined NO_WAITPID
633 633
    result = wait(data);
634 634
#elif defined HAVE_WAITPID
635
#ifdef __APPLE__
636
    if (arg->flags & WNOHANG) {
637
	result = waitpid(arg->pid, arg->st, arg->flags);
638
    } else {
639
	result = 0;
640
	while (result == 0) {
641
	    result = waitpid(arg->pid, arg->st, arg->flags | WNOHANG);
642
	    if (result == 0) {
643
		usleep(10000);
644
	    }
645
	}
646
    }
647
#else
635 648
    result = waitpid(arg->pid, arg->st, arg->flags);
649
#endif
636 650
#else  /* HAVE_WAIT4 */
637 651
    result = wait4(arg->pid, arg->st, arg->flags, NULL);
638 652
#endif
......
2644 2658

  
2645 2659
/*
2646 2660
 *  call-seq:
2661
 *     Process.fork_supported?   # => boolean
2662
 *
2663
 *  Returns whether forking subprocesses is supported on the current platform.
2664
 *  If not, then it indicates that <code>Kernel.fork</code> and
2665
 *  <code>Process.fork</code> will raise NotImplementedError.
2666
 */
2667

  
2668
static VALUE
2669
rb_f_fork_supported_p(VALUE obj)
2670
{
2671
#if defined(HAVE_FORK) && !defined(CANNOT_FORK_WITH_PTHREAD)
2672
    return Qtrue;
2673
#else
2674
    return Qfalse;
2675
#endif
2676
}
2677

  
2678
/*
2679
 *  call-seq:
2647 2680
 *     Process.exit!(fixnum=-1)
2648 2681
 *
2649 2682
 *  Exits the process immediately. No exit handlers are
......
5428 5461

  
5429 5462
    rb_define_singleton_method(rb_mProcess, "exec", rb_f_exec, -1);
5430 5463
    rb_define_singleton_method(rb_mProcess, "fork", rb_f_fork, 0);
5464
    rb_define_singleton_method(rb_mProcess, "fork_supported?", rb_f_fork_supported_p, 0);
5431 5465
    rb_define_singleton_method(rb_mProcess, "spawn", rb_f_spawn, -1);
5432 5466
    rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1);
5433 5467
    rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1);
5434
-