The Process
module is a collection of methods used to manipulate processes.
PRIO_PGRP |
1 | Process Group priority. |
PRIO_PROCESS |
0 | Process priority. |
PRIO_USER |
2 | User priority. |
WNOHANG |
1 | Do not block if no child has exited. Not available on all platforms. |
WUNTRACED |
2 | Return stopped children as well. Not available on all platforms. |
Process.egid → 500
Process.euid → 501
Process.exit!(0)
nil
Kernel::fork
.
Process.getpgid(Process.ppid()) → 32438
Process.getpgid(0) → 32438
Process.getpgrp → 32438
Process::PRIO_PGRP
,
Process::PRIO_USER
, or Process::PRIO_PROCESS
.
anInteger is an id indicating the particular process,
process group, or user (an id of 0 means current).
Lower priorities are more favorable for
scheduling. Not available on all platforms.
Process.getpriority(Process::PRIO_USER, 0) → 0
Process.getpriority(Process::PRIO_PROCESS, 0) → 0
Process.gid → 500
SIG
prefix). If aSignal is negative (or
starts with a “-
” sign), kills process groups instead
of processes. Not all signals are available on all platforms.
trap("SIGHUP") { close_then_exit }
Process.kill("SIGHUP", 0)
Process.pid → 1488
print "I am ", Process.pid, "\n"
Process.fork { print "Dad is ", Process.ppid, "\n" }
produces:
I am 1490
Dad is 1490
setpgid(0,0)
.
Not available on all platforms.
Process#getpriority
.
Process.setpriority(Process::PRIO_USER, 0, 19) → 0
Process.setpriority(Process::PRIO_PROCESS, 0, 19) → 0
Process.getpriority(Process::PRIO_USER, 0) → 19
Process.getpriority(Process::PRIO_PROCESS, 0) → 19
Process.setsid → 1495
Process.uid → 501
SystemError
if there are no child processes.
Not available on all platforms.
Process.fork { exit 1; } → 1500
Process.wait → 1500
SystemError
if there are no child processes.
Process.fork { exit 1 } → 1503
Process.wait2 → [1503, 256]
Process::WNOHANG
(do not block if no child available)
or Process::WUNTRACED
(return stopped children that haven't
been reported).
Not all flags are available on all platforms, but a flag value
of zero will work on all platforms.
include Process
pid = fork { sleep 3 } → 1506
Time.now → Sun Jun 09 00:20:09 CDT 2002
waitpid(pid, Process::WNOHANG) → nil
Time.now → Sun Jun 09 00:20:09 CDT 2002
waitpid(pid, 0) → 1506
Time.now → Sun Jun 09 00:20:12 CDT 2002
Process::WNOHANG
(do not block if no child available)
or Process::WUNTRACED
(return stopped children that haven't
been reported).
Not all flags are available on all platforms, but a flag value
of zero will work on all platforms.Extracted from the book "Programming Ruby - The Pragmatic Programmer's Guide"
Copyright © 2001 by Addison Wesley Longman, Inc. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/).
Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder.
Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.