Returns a topologically sorted array of nodes. The array is sorted from children to parents, i.e. the first element has no child and the last node has no parent.
The graph is represented by each_node and each_child. each_node should have call
method which yields for each node in the graph. each_child should have call
method which takes a node argument and yields for each child node.
If there is a cycle, TSort::Cyclic
is raised.
g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]} each_node = lambda {|&b| g.each_key(&b) } each_child = lambda {|n, &b| g[n].each(&b) } p TSort.tsort(each_node, each_child) #=> [4, 2, 3, 1] g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]} each_node = lambda {|&b| g.each_key(&b) } each_child = lambda {|n, &b| g[n].each(&b) } p TSort.tsort(each_node, each_child) # raises TSort::Cyclic
Returns a 2-element array containing the normalized signed float fraction
and integer exponent
of x
such that:
x = fraction * 2**exponent
See IEEE 754 double-precision binary floating-point format: binary64.
Domain: [-INFINITY, INFINITY]
.
Range
[-INFINITY, INFINITY]
.
Examples:
frexp(-INFINITY) # => [-Infinity, -1] frexp(-2.0) # => [-0.5, 2] frexp(-1.0) # => [-0.5, 1] frexp(0.0) # => [0.0, 0] frexp(1.0) # => [0.5, 1] frexp(2.0) # => [0.5, 2] frexp(INFINITY) # => [Infinity, -1]
Related: Math.ldexp
(inverse of Math.frexp
).
Creates a child process.
With a block given, runs the block in the child process; on block exit, the child terminates with a status of zero:
puts "Before the fork: #{Process.pid}" fork do puts "In the child process: #{Process.pid}" end # => 382141 puts "After the fork: #{Process.pid}"
Output:
Before the fork: 420496 After the fork: 420496 In the child process: 420520
With no block given, the fork
call returns twice:
Once in the parent process, returning the pid of the child process.
Once in the child process, returning nil
.
Example:
puts "This is the first line before the fork (pid #{Process.pid})" puts fork puts "This is the second line after the fork (pid #{Process.pid})"
Output:
This is the first line before the fork (pid 420199) 420223 This is the second line after the fork (pid 420199) This is the second line after the fork (pid 420223)
In either case, the child process may exit using Kernel.exit!
to avoid the call to Kernel#at_exit
.
To avoid zombie processes, the parent process should call either:
Process.wait
, to collect the termination statuses of its children.
Process.detach
, to register disinterest in their status.
The thread calling fork
is the only thread in the created child process; fork
doesn’t copy other threads.
Note that method fork
is available on some platforms, but not on others:
Process.respond_to?(:fork) # => true # Would be false on some.
If not, you may use ::spawn
instead of fork
.
Terminates execution immediately, effectively by calling Kernel.exit(false)
.
If string argument msg
is given, it is written to STDERR prior to termination; otherwise, if an exception was raised, prints its message and backtrace.
An internal API for fork. Do not call this method directly. Currently, this is called via Kernel#fork
, Process.fork
, and IO.popen
with "-"
.
This method is not for casual code but for application monitoring libraries. You can add custom code before and after fork events by overriding this method.
Note: Process.daemon
may be implemented using fork(2) BUT does not go through this method. Thus, depending on your reason to hook into this method, you may also want to hook into that one. See this issue for a more detailed discussion of this.
Returns the scheduling priority for specified process, process group, or user.
Argument kind
is one of:
Process::PRIO_PROCESS
: return priority for process.
Process::PRIO_PGRP
: return priority for process group.
Process::PRIO_USER
: return priority for user.
Argument id
is the ID for the process, process group, or user; zero specified the current ID for kind
.
Examples:
Process.getpriority(Process::PRIO_USER, 0) # => 19 Process.getpriority(Process::PRIO_PROCESS, 0) # => 19
Not available on all platforms.
See Process.getpriority
.
Examples:
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
Not available on all platforms.
Sets the supplemental group access list; the new list includes:
The group IDs of those groups to which the user given by username
belongs.
The group ID gid
.
Example:
Process.groups # => [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27] Process.initgroups('me', 30) # => [30, 6, 10, 11] Process.groups # => [30, 6, 10, 11]
Not available on all platforms.
Returns an array of the group IDs in the supplemental group access list for the current process:
Process.groups # => [4, 24, 27, 30, 46, 122, 135, 136, 1000]
These properties of the returned array are system-dependent:
Whether (and how) the array is sorted.
Whether the array includes effective group IDs.
Whether the array includes duplicate group IDs.
Whether the array size exceeds the value of Process.maxgroups
.
Use this call to get a sorted and unique array:
Process.groups.uniq.sort
Sets the supplemental group access list to the given array of group IDs.
Process.groups # => [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27] Process.groups = [27, 6, 10, 11] # => [27, 6, 10, 11] Process.groups # => [27, 6, 10, 11]
Returns the maximum number of group IDs allowed in the supplemental group access list:
Process.maxgroups # => 32
Sets the maximum number of group IDs allowed in the supplemental group access list.
Returns a list of signal names mapped to the corresponding underlying signal numbers.
Signal.list #=> {"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "IOT"=>6, "ABRT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
Returns the generator of the group.
See the OpenSSL
documentation for EC_GROUP_get0_generator()
Returns the cofactor of the group.
See the OpenSSL
documentation for EC_GROUP_get_cofactor()
Foo += bar ^^^^^^^^^^^
def foo(**bar); end
^^^^^
def foo(**); end
^^
Example:
x.foo += 42 ^^^ (for foo) x.foo += 42 ^ (for +) x.foo += 42 ^^^^^^^ (for foo=)
Example:
x[1] += 42 ^^^ (for []) x[1] += 42 ^ (for +) x[1] += 42 ^^^^^^ (for []=)