Programming Ruby
The Pragmatic Programmer's Guide
module Process
Index:
egid
egid=
euid
euid=
exit!
fork
getpgid
getpgrp
getpriority
gid
gid=
kill
pid
ppid
setpgid
setpgrp
setpriority
setsid
uid
uid=
wait
wait2
waitpid
waitpid2
The
Process module is a collection of methods used to manipulate
processes.
constants
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.
class methods
egid
Process.egid
->
aFixnum
Returns the effective group id for this process.
Process.egid
サ
500
egid=
Process.egid=
aFixnum
->
aFixnum
Sets the effective group id for this process.
euid
Process.euid
->
aFixnum
Returns the effective user id for this process.
Process.euid
サ
501
euid=
Process.euid=
aFixnum
Sets the effective user id for this process.
Not available on all platforms.
exit!
Process.exit!(
aFixnum=-1 )
Exits the process immediately.
No exit handlers are run.
aFixnum is returned to the underlying system as the exit
status.
fork
Process.fork
[{ block }
]
->
aFixnum or
nil
See
Kernel::fork
on page 416.
getpgid
Process.getpgid(
anInteger )
->
anInteger
Returns the process group id for the given process id.
Not available on all platforms.
Process.getpgid(Process.ppid())
サ
32438
getpgrp
Process.getpgrp
->
anInteger
Returns the process group id for this process.
Not available on all platforms.
Process.getpgid(0)
サ
32438
Process.getpgrp
サ
32438
getpriority
Process.getpriority(
aKind,
anInteger ) ->
aFixnum
Gets the
scheduling priority for specified process, process group, or
user.
aKind indicates the kind of entity to find:
one of
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
gid
Process.gid
->
aFixnum
Returns the group id for this process.
Process.gid
サ
500
gid=
Process.gid=
aFixnum
->
aFixnum
Sets the group id for this process.
kill
Process.kill(
aSignal,
[
aPid
]+
) ->
aFixnum
Sends the given signal to the specified process id(s),
or to the
current process if
aPid is zero.
aSignal may be an
integer signal number or a POSIX signal name (either with or
without a
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)
pid
Process.pid ->
aFixnum
Returns the process id of this process.
Not available on all platforms.
Process.pid
サ
1488
ppid
Process.ppid ->
aFixnum
Returns the process id of the parent of this process.
Always returns 0 on NT.
Not available on all platforms.
print "I am ", Process.pid, "\n"
Process.fork { print "Dad is ", Process.ppid, "\n" }
produces:
setpgid
Process.setpgid(
aPid,
anInteger )
-> 0
Sets the process group id of
aPid (0 indicates this
process) to
anInteger.
Not available on all platforms.
Equivalent to
setpgid(0,0).
Not available on all platforms.
setpriority
Process.setpriority(
kind,
anInteger,
anIntPriority )
-> 0
See
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
setsid
Process.setsid
->
aFixnum
Establishes this process as a new session and process group
leader, with no controlling tty.
Returns the session id.
Not available on all platforms.
Process.setsid
サ
1495
uid
Process.uid
->
aFixnum
Returns the user id of this process.
Process.uid
サ
501
uid=
Process.uid=
anInteger
->
aNumeric
Sets the (integer) user id for this process.
Not available on all platforms.
wait
Process.wait
->
aFixnum
Waits for any child process to exit and returns the process id
of that child.
Raises a
SystemError if there are no child processes.
Not available on all platforms.
Process.fork { exit 1; }
サ
1500
Process.wait
サ
1500
wait2
Process.wait2
->
anArray
Waits for any child process to exit and returns an array
containing the process id and the exit status
of that child.
Raises a
SystemError if there are no child processes.
Process.fork { exit 1 }
サ
1503
Process.wait2
サ
[1503, 256]
waitpid
Process.waitpid(
aPid,
anInteger=0 )
->
aPid
Waits for the given child process to exit.
anInteger may be
a logical or of the flag value
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
waitpid2
Process.waitpid2(
aPid,
anInteger=0 )
->
anArray
Waits for the given child process to exit, returning that
child's process id and exit status.
anInteger may be
a logical or of the flag value
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.