6
$Date: 2007-03-20 09:12:51 +0900 (火, 20 3月 2007) $
6
$Date: 2007-08-28 01:48:14 +0900 (火, 28 8月 2007) $
7
7
created at: Tue Aug 10 14:30:50 JST 1993
9
Copyright (C) 1993-2003 Yukihiro Matsumoto
9
Copyright (C) 1993-2007 Yukihiro Matsumoto
10
10
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
11
11
Copyright (C) 2000 Information-technology Promotion Agency, Japan
13
13
**********************************************************************/
15
#include "ruby/ruby.h"
16
#include "ruby/signal.h"
830
830
st_foreach(pid_tbl, waitall_each, result);
833
rb_last_status_clear();
833
836
for (pid = -1;;) {
834
838
pid = wait(&status);
840
pid = rb_waitpid(-1, &status, 0);
836
843
if (errno == ECHILD)
838
846
if (errno == EINTR) {
839
847
rb_thread_schedule();
844
854
rb_last_status_set(status, pid);
845
rb_ary_push(result, rb_assoc_new(PIDT2NUM(pid), rb_last_status_get()));
848
rb_last_status_clear();
850
pid = rb_waitpid(-1, &status, 0);
856
rb_ary_push(result, rb_assoc_new(PIDT2NUM(pid), rb_last_status_get()));
856
rb_ary_push(result, rb_assoc_new(PIDT2NUM(pid), rb_last_status_get()));
863
detach_process_watcher(int *pid_p)
862
detach_process_watcher(void *arg)
864
rb_pid_t cpid, pid = (rb_pid_t)arg;
869
cpid = rb_waitpid(*pid_p, &status, WNOHANG);
870
if (cpid != 0) return rb_last_status_get();
867
while ((cpid = rb_waitpid(pid, &status, 0)) == 0) {
868
/* wait while alive */
870
return rb_last_status_get();
876
874
rb_detach_process(rb_pid_t pid)
878
return rb_thread_create(detach_process_watcher, (void*)&pid);
876
return rb_thread_create(detach_process_watcher, (void*)pid);
891
889
* separate Ruby thread whose sole job is to reap the status of the
892
890
* process _pid_ when it terminates. Use <code>detach</code>
893
891
* only when you do not intent to explicitly wait for the child to
894
* terminate. <code>detach</code> only checks the status
895
* periodically (currently once each second).
897
894
* The waiting thread returns the exit status of the detached process
898
895
* when it terminates, so you can use <code>Thread#join</code> to
1082
1081
ss = ALLOCA_N(char, s-str+1);
1083
1082
memcpy(ss, str, s-str);
1084
1083
ss[s-str] = '\0';
1085
if (*a++ = strtok(ss, " \t")) {
1086
while (t = strtok(NULL, " \t")) {
1084
if ((*a++ = strtok(ss, " \t")) != 0) {
1085
while ((t = strtok(NULL, " \t")) != 0) {
1293
1292
#ifndef FD_CLOEXEC
1294
1293
preserving_errno({
1295
1294
fprintf(stderr, "%s:%d: command not found: %s\n",
1296
ruby_sourcefile, ruby_sourceline, prog);
1295
rb_sourcefile(), rb_sourceline(), prog);
1524
1523
return Qnil; /* not reached */
1529
if (GET_THREAD()->tag) {
1532
args[0] = INT2NUM(status);
1533
args[1] = rb_str_new2("exit");
1534
rb_exc_raise(rb_class_new_instance(2, args, rb_eSystemExit));
1544
* Kernel::exit(integer=0)
1545
* Process::exit(integer=0)
1547
* Initiates the termination of the Ruby script by raising the
1548
* <code>SystemExit</code> exception. This exception may be caught. The
1549
* optional parameter is used to return a status code to the invoking
1554
* puts "never get here"
1556
* puts "rescued a SystemExit exception"
1558
* puts "after begin block"
1560
* <em>produces:</em>
1562
* rescued a SystemExit exception
1565
* Just prior to termination, Ruby executes any <code>at_exit</code> functions
1566
* (see Kernel::at_exit) and runs any object finalizers (see
1567
* ObjectSpace::define_finalizer).
1569
* at_exit { puts "at_exit function" }
1570
* ObjectSpace.define_finalizer("string", proc { puts "in finalizer" })
1573
* <em>produces:</em>
1580
rb_f_exit(int argc, VALUE *argv)
1586
if (rb_scan_args(argc, argv, "01", &status) == 1) {
1589
istatus = EXIT_SUCCESS;
1592
istatus = EXIT_FAILURE;
1595
istatus = NUM2INT(status);
1596
#if EXIT_SUCCESS != 0
1598
istatus = EXIT_SUCCESS;
1604
istatus = EXIT_SUCCESS;
1607
return Qnil; /* not reached */
1617
* Terminate execution immediately, effectively by calling
1618
* <code>Kernel.exit(1)</code>. If _msg_ is given, it is written
1619
* to STDERR prior to terminating.
1623
rb_f_abort(int argc, VALUE *argv)
1625
extern void ruby_error_print(void);
1629
if (!NIL_P(GET_THREAD()->errinfo)) {
1632
rb_exit(EXIT_FAILURE);
1637
rb_scan_args(argc, argv, "1", &args[1]);
1638
StringValue(argv[0]);
1639
rb_io_puts(argc, argv, rb_stderr);
1640
args[0] = INT2NUM(EXIT_FAILURE);
1641
rb_exc_raise(rb_class_new_instance(2, args, rb_eSystemExit));
1643
return Qnil; /* not reached */
1527
1647
#if defined(sun)
1528
1648
#define signal(a,b) sigset(a,b)
3669
3789
rb_define_global_function("system", rb_f_system, -1);
3670
3790
rb_define_global_function("spawn", rb_f_spawn, -1);
3671
3791
rb_define_global_function("sleep", rb_f_sleep, -1);
3792
rb_define_global_function("exit", rb_f_exit, -1);
3793
rb_define_global_function("abort", rb_f_abort, -1);
3673
3795
rb_mProcess = rb_define_module("Process");
3689
3811
rb_define_singleton_method(rb_mProcess, "fork", rb_f_fork, 0);
3690
3812
rb_define_singleton_method(rb_mProcess, "spawn", rb_f_spawn, -1);
3691
3813
rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1);
3692
rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1); /* in eval.c */
3693
rb_define_singleton_method(rb_mProcess, "abort", rb_f_abort, -1); /* in eval.c */
3814
rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1);
3815
rb_define_singleton_method(rb_mProcess, "abort", rb_f_abort, -1);
3695
3817
rb_define_module_function(rb_mProcess, "kill", rb_f_kill, -1); /* in signal.c */
3696
3818
rb_define_module_function(rb_mProcess, "wait", proc_wait, -1);
3824
3946
rb_define_module_function(rb_mProcGID, "change_privilege", p_gid_change_privilege, 1);
3825
3947
rb_define_module_function(rb_mProcUID, "grant_privilege", p_uid_grant_privilege, 1);
3826
3948
rb_define_module_function(rb_mProcGID, "grant_privilege", p_gid_grant_privilege, 1);
3827
rb_define_alias(rb_mProcUID, "eid=", "grant_privilege");
3828
rb_define_alias(rb_mProcGID, "eid=", "grant_privilege");
3949
rb_define_alias(rb_singleton_class(rb_mProcUID), "eid=", "grant_privilege");
3950
rb_define_alias(rb_singleton_class(rb_mProcGID), "eid=", "grant_privilege");
3829
3951
rb_define_module_function(rb_mProcUID, "re_exchange", p_uid_exchange, 0);
3830
3952
rb_define_module_function(rb_mProcGID, "re_exchange", p_gid_exchange, 0);
3831
3953
rb_define_module_function(rb_mProcUID, "re_exchangeable?", p_uid_exchangeable, 0);