path: root/process.c
AgeCommit message (Collapse)Author
2021-02-09Expose scheduler as public interface & bug fixes. (#3945)Samuel Williams
* Rename `rb_scheduler` to `rb_fiber_scheduler`. * Use public interface if available. * Use `rb_check_funcall` where possible. * Don't use `unblock` unless the fiber was non-blocking. Notes: Merged-By: ioquatix <>
2020-12-24Updated access to Process::Status attributesNobuyoshi Nakada
pst_pid() no longer returns Qnil even if the receiver is not initialized.
2020-12-24Store errno in struct rb_process_statusNobuyoshi Nakada
To propagate errno in the fiber thread scheduler hook. Returns nil when no terminated process. Notes: Merged:
2020-12-22Struct::Tms: delete卜部昌平
Has been deprecated since 44c53ee473d3b3973cb5c3ce03fbf4f280fd75ff. Notes: Merged:
2020-12-21Fixed indefinite articles before "Integer" [ci skip]Nobuyoshi Nakada
2020-12-19Remove unused variableRadosław Bułat
Notes: Merged:
2020-12-18Revert "Better cooperation between public/protected/private with attr* and ↵Yusuke Endoh
alias_method" This reverts commit 81739ad4fdfcc86a769056fec352f27c686fba1b.
2020-12-17Better cooperation between public/protected/private with attr* and alias_methodRadosław Bułat
Notes: Merged:
2020-12-16Fixed marshal compatibility of Process::StatusNobuyoshi Nakada
2020-12-12[DOC] Process::Status.wait return nil if no child processes [ci skip]Nobuyoshi Nakada
2020-12-11RDoc states that Process::Status.wait returns nil if cannot waitNobuyoshi Nakada
2020-12-11[DOC] Fixed the RDoc location of Process::Status.wait [ci skip]Nobuyoshi Nakada
2020-12-11[DOC] Moved RDoc of abort [ci skip]Nobuyoshi Nakada
2020-12-09Tweaked `Process::Status.wait`Nobuyoshi Nakada
* revert `rb_last_status_set` * renamed the new function as `rb_process_status_new` * `rb_process_status_new` always freezes the return value * marked `Process::Status.wait` as EXPERIMENTAL, as it has not been discussed totally yet.
2020-12-09Add support for non-blocking `Process.wait`.Samuel Williams
Notes: Merged:
2020-12-07Revert getaddrinfo_a()Masaki Matsushita
getaddrinfo_a() gets stuck after fork(). To avoid this, we need 1 second sleep to wait for internal worker threads of getaddrinfo_a() to be finished, but that is unacceptable. [Bug #17220] [Feature #17134] [Feature #17187]
2020-12-06Call cleanup function for getaddrinfo_a(3) only before fork()Masaki Matsushita
Previously, rb_getaddrinfo_a_before_exec() is called from before_exec(). However, the function needs to be called only before fork(). The change moves it to before_fork().
2020-12-04Add a hook before fork() for getaddrinfo_a()Masaki Matsushita
We need stop worker threads in getaddrinfo_a() before fork(). This change adds a hook before fork() that cancel all outstanding requests and wait for all ongoing requests. Then, it waits for all worker threads to be finished. Fixes [Bug #17220]
2020-11-22Remove obsoleted internal/mjit.h inclusionTakashi Kokubun
2020-11-18fix public interfaceKoichi Sasada
To make some kind of Ractor related extensions, some functions should be exposed. * include/ruby/thread_native.h * rb_native_mutex_* * rb_native_cond_* * include/ruby/ractor.h * RB_OBJ_SHAREABLE_P(obj) * rb_ractor_shareable_p(obj) * rb_ractor_std*() * rb_cRactor and rm ractor_pub.h and rename srcdir/ractor.h to srcdir/ractor_core.h (to avoid conflict with include/ruby/ractor.h) Notes: Merged:
2020-11-07Rename to `Fiber#set_scheduler`.Samuel Williams
Notes: Merged:
2020-10-27freeze Process::StatusKoichi Sasada
It seems immutable information. Notes: Merged:
2020-10-21Don't redefine #rb_intern over and over againStefan Stüben
Notes: Merged:
2020-10-20Some global variables can be accessed from ractorsKoichi Sasada
Some global variables should be used from non-main Ractors. [Bug #17268] ```ruby # ractor-local (derived from created ractor): debug '$DEBUG' => $DEBUG, '$-d' => $-d, # ractor-local (derived from created ractor): verbose '$VERBOSE' => $VERBOSE, '$-w' => $-w, '$-W' => $-W, '$-v' => $-v, # process-local (readonly): other commandline parameters '$-p' => $-p, '$-l' => $-l, '$-a' => $-a, # process-local (readonly): getpid '$$' => $$, # thread local: process result '$?' => $?, # scope local: match '$~' => $~.inspect, '$&' => $&, '$`' => $`, '$\'' => $', '$+' => $+, '$1' => $1, # scope local: last line '$_' => $_, # scope local: last backtrace '$@' => $@, '$!' => $!, # ractor local: stdin, out, err '$stdin' => $stdin.inspect, '$stdout' => $stdout.inspect, '$stderr' => $stderr.inspect, ``` Notes: Merged:
2020-09-14Prefer `rb_thread_current_scheduler`.Samuel Williams
Notes: Merged:
2020-09-14Standardised scheduler interface.Samuel Williams
Notes: Merged:
2020-09-03Introduce Ractor mechanism for parallel executionKoichi Sasada
This commit introduces Ractor mechanism to run Ruby program in parallel. See doc/ for more details about Ractor. See ticket [Feature #17100] to see the implementation details and discussions. [Feature #17100] This commit does not complete the implementation. You can find many bugs on using Ractor. Also the specification will be changed so that this feature is experimental. You will see a warning when you make the first Ractor with ``. I hope this feature can help programmers from thread-safety issues. Notes: Merged:
2020-08-22Fix type of getlogin_r's 2nd argumentKazuhiro NISHIYAMA ``` process.c:5593:37: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32] while ((gle = getlogin_r(login, loginsize)) != 0) { ~~~~~~~~~~ ^~~~~~~~~ ``` type of getlogin_r's 2nd argument is - int on FreeBSD - - size_t on Linux, NetBSD - -
2020-07-20Rename `rb_current_thread_scheduler` to `rb_thread_scheduler_if_nonblocking`.Samuel Williams
Correctly capture thread before releasing GVL and pass as argument to `rb_thread_scheduler_if_nonblocking`. Notes: Merged:
2020-06-29add UNREACHABLE_RETURN卜部昌平
Not every compilers understand that rb_raise does not return. When a function does not end with a return statement, such compilers can issue warnings. We would better tell them about reachabilities. Notes: Merged:
2020-06-29check_exec_redirect: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged:
2020-06-29check_exec_redirect_fd: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged:
2020-06-09Use the dedicated conversion macroNobuyoshi Nakada
2020-06-09Return seconds slept after Thread.scheduler wait_sleepnicholas a. evans
Kernel#sleep should still return seconds slept, even when using a Thread.scheduler. The return value of Scheduler#wait_sleep can be ignored. Notes: Merged:
2020-05-23Allow Dir.home to work for non-login procs when $HOME not setAlan D. Salewski
Allow the 'Dir.home' method to reliably locate the user's home directory when all three of the following are true at the same time: 1. Ruby is running on a Unix-like OS 2. The $HOME environment variable is not set 3. The process is not a descendant of login(1) (or a work-alike) The prior behavior was that the lookup could only work for login-descended processes. This is accomplished by looking up the user's record in the password database by uid (getpwuid_r(3)) as a fallback to the lookup by name (getpwname_r(3)) which is still attempted first (based on the name, if any, returned by getlogin_r(3)). If getlogin_r(3), getpwnam_r(3), and/or getpwuid_r(3) is not available at compile time, will fallback on using their respective non-*_r() variants: getlogin(3), getpwnam(3), and/or getpwuid(3). The rationale for attempting to do the lookup by name prior to doing it by uid is to accommodate the possibility of multiple login names (each with its own record in the password database, so each with a potentially different home directory) being mapped to the same uid (as is explicitly allowed for by POSIX; see getlogin(3posix)). Preserves the existing behavior for login-descended processes, and adds the new capability of having Dir.home being able to find the user's home directory for non-login-descended processes. Fixes [Bug #16787] Related discussion:
2020-05-14Thread scheduler for light weight concurrency.Samuel Williams
Notes: Merged: Merged-By: ioquatix <>
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged:
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged:
2020-05-11Added more NORETURN declarationsNobuyoshi Nakada
2020-05-10Run rb_syswait on exec failureTakashi Kokubun
not only when !w but also when w == WAITPID_LOCK_ONLY. See also: f7c0cc36920a4ed14a3ab1ca6cfdf18ceff1e5d5 and a2264342063260d660b99872eaf5080f6ab08e81. We thought this change was an oversight in the latter commit. Without this change, the test fails like: $ make test-all TESTS="../test/ruby/test_process.rb -n test_exec_failure_leaves_no_child" RUN_OPTS="--jit" ... 1) Failure: TestProcess#test_exec_failure_leaves_no_child [/home/k0kubun/src/]: Expected [[26799, #<Process::Status: pid 26799 exit 127>]] to be empty. Co-Authored-By: Yusuke Endoh <>
2020-05-02internal/process.h: add a no-warning simple wrapper for fork(2)Yusuke Endoh
As fork(2) is deprecated, its calls must be guarded by `COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)`. All usages of fork(2) in process have been alread guarded. A new call to fork(2) was added in ruby.c with f22c4ff359498ab342e4b6d6feb21af6004ee270. This caused a build failure on Solaris 11. It may hide a bug to guard big code unnecessarily, so this change introduces a simple wrapper "rb_fork" whose definition is guarded, and replaces all calls to fork(2) with the wrapper function.
2020-04-21__GNUC__ is too lax卜部昌平
Ditto for 4b853932eaa7fa4acf8a0f0c9b7c695bb4f5e76d
2020-04-16Preserve encoding in error messages for invalid user/group nameNobuyoshi Nakada
2020-04-16Preserve encoding in error message for invalid env exec optionNobuyoshi Nakada
2020-04-13Add a a list of cases for which clock_getres() has been observed to be ↵Benoit Daloze
inaccurate * See [Bug #16740]
2020-04-10[DOC] Fixed POSIX clock_getres(3) link [ci skip]Nobuyoshi Nakada
It should not be linked to `Process.clock_getes`.
2020-04-10Warn about Process#clock_getres being unreliable in documentationBenoit Daloze
* [Bug #16740] * Remove the GETTIMEOFDAY_BASED_CLOCK_REALTIME example because the caveat applies to all clock ids, not just the Symbol clock ids.
2020-04-08Suppress -Wswitch warningsNobuyoshi Nakada
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <>
2020-02-12Fixed a potential memory leakNobuyoshi Nakada
`rb_str_new_cstr` can raise a `NoMemoryError`.