Safely write a file in binary mode on all platforms.
Start a dRuby server locally.
The new dRuby server will become the primary server, even if another server is currently the primary server.
uri
is the URI
for the server to bind to. If nil, the server will bind to random port on the default local host name and use the default dRuby protocol.
front
is the server’s front object. This may be nil.
config
is the configuration for the new server. This may be nil.
See DRbServer::new
.
Start a dRuby server locally.
The new dRuby server will become the primary server, even if another server is currently the primary server.
uri
is the URI
for the server to bind to. If nil, the server will bind to random port on the default local host name and use the default dRuby protocol.
front
is the server’s front object. This may be nil.
config
is the configuration for the new server. This may be nil.
See DRbServer::new
.
Stop the local dRuby server.
This operates on the primary server. If there is no primary server currently running, it is a noop.
Stop the local dRuby server.
This operates on the primary server. If there is no primary server currently running, it is a noop.
Registers server
with DRb
.
This is called when a new DRb::DRbServer is created.
If there is no primary server then server
becomes the primary server.
Example:
require 'drb' s = DRb::DRbServer.new # automatically calls regist_server DRb.fetch_server s.uri #=> #<DRb::DRbServer:0x...>
Registers server
with DRb
.
This is called when a new DRb::DRbServer is created.
If there is no primary server then server
becomes the primary server.
Example:
require 'drb' s = DRb::DRbServer.new # automatically calls regist_server DRb.fetch_server s.uri #=> #<DRb::DRbServer:0x...>
Hard links a file system entry src
to dest
. If src
is a directory, this method links its contents recursively.
Both of src
and dest
must be a path name. src
must exist, dest
must not exist.
If dereference_root
is true, this method dereferences the tree root.
If remove_destination
is true, this method removes each destination file before copy.
Hard links a file system entry src
to dest
. If src
is a directory, this method links its contents recursively.
Both of src
and dest
must be a path name. src
must exist, dest
must not exist.
If dereference_root
is true, this method dereferences the tree root.
If remove_destination
is true, this method removes each destination file before copy.
Copies a file system entry src
to dest
. If src
is a directory, this method copies its contents recursively. This method preserves file types, c.f. symlink, directory… (FIFO, device files and etc. are not supported yet)
Both of src
and dest
must be a path name. src
must exist, dest
must not exist.
If preserve
is true, this method preserves owner, group, and modified time. Permissions are copied regardless preserve
.
If dereference_root
is true, this method dereference tree root.
If remove_destination
is true, this method removes each destination file before copy.
Copies a file system entry src
to dest
. If src
is a directory, this method copies its contents recursively. This method preserves file types, c.f. symlink, directory… (FIFO, device files and etc. are not supported yet)
Both of src
and dest
must be a path name. src
must exist, dest
must not exist.
If preserve
is true, this method preserves owner, group, and modified time. Permissions are copied regardless preserve
.
If dereference_root
is true, this method dereference tree root.
If remove_destination
is true, this method removes each destination file before copy.
This method removes a file system entry path
. path
might be a regular file, a directory, or something. If path
is a directory, remove it recursively.
See also remove_entry_secure.
This method removes a file system entry path
. path
might be a regular file, a directory, or something. If path
is a directory, remove it recursively.
See also remove_entry_secure.
Takes a hash as its argument. The key is a symbol or an array of symbols. These symbols correspond to method names, instance variable names, or constant names (see def_delegator
). The value is the accessor to which the methods will be delegated.
Returns whether or not the constant const
is defined. You may optionally pass the type
of const
as [const, type]
, such as:
have_const(%w[PTHREAD_MUTEX_INITIALIZER pthread_mutex_t], "pthread.h")
You may also pass additional headers
to check against in addition to the common header files, and additional flags to opt
which are then passed along to the compiler.
If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with HAVE_CONST_
.
For example, if have_const('foo')
returned true, then the HAVE_CONST_FOO
preprocessor macro would be passed to the compiler.
Returns a Hash
of the defined schemes.
Open3.pipeline_rw
starts a list of commands as a pipeline with pipes which connect to stdin of the first command and stdout of the last command.
Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) {|first_stdin, last_stdout, wait_threads| ... } first_stdin, last_stdout, wait_threads = Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) ... first_stdin.close last_stdout.close
Each cmd is a string or an array. If it is an array, the elements are passed to Process.spawn
.
cmd: commandline command line string which is passed to a shell [env, commandline, opts] command line string which is passed to a shell [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell) [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell) Note that env and opts are optional, as for Process.spawn.
The options to pass to Process.spawn
are constructed by merging opts
, the last hash element of the array, and specifications for the pipes between each of the commands.
Example:
Open3.pipeline_rw("tr -dc A-Za-z", "wc -c") {|i, o, ts| i.puts "All persons more than a mile high to leave the court." i.close p o.gets #=> "42\n" } Open3.pipeline_rw("sort", "cat -n") {|stdin, stdout, wait_thrs| stdin.puts "foo" stdin.puts "bar" stdin.puts "baz" stdin.close # send EOF to sort. p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n" }
Open3.pipeline_rw
starts a list of commands as a pipeline with pipes which connect to stdin of the first command and stdout of the last command.
Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) {|first_stdin, last_stdout, wait_threads| ... } first_stdin, last_stdout, wait_threads = Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) ... first_stdin.close last_stdout.close
Each cmd is a string or an array. If it is an array, the elements are passed to Process.spawn
.
cmd: commandline command line string which is passed to a shell [env, commandline, opts] command line string which is passed to a shell [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell) [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell) Note that env and opts are optional, as for Process.spawn.
The options to pass to Process.spawn
are constructed by merging opts
, the last hash element of the array, and specifications for the pipes between each of the commands.
Example:
Open3.pipeline_rw("tr -dc A-Za-z", "wc -c") {|i, o, ts| i.puts "All persons more than a mile high to leave the court." i.close p o.gets #=> "42\n" } Open3.pipeline_rw("sort", "cat -n") {|stdin, stdout, wait_thrs| stdin.puts "foo" stdin.puts "bar" stdin.puts "baz" stdin.close # send EOF to sort. p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n" }
Returns the time resolution returned by POSIX clock_getres
() function.
clock_id
specifies a kind of clock. See the document of Process.clock_gettime
for details.
clock_id
can be a symbol as Process.clock_gettime
. However the result may not be accurate. For example, Process.clock_getres(:GETTIMEOFDAY_BASED_CLOCK_REALTIME)
returns 1.0e-06 which means 1 microsecond, but actual resolution can be more coarse.
If the given clock_id
is not supported, Errno::EINVAL is raised.
unit
specifies a type of the return value. Process.clock_getres
accepts unit
as Process.clock_gettime
. The default value, :float_second
, is also same as Process.clock_gettime
.
Process.clock_getres
also accepts :hertz
as unit
. :hertz
means a the reciprocal of :float_second
.
:hertz
can be used to obtain the exact value of the clock ticks per second for times() function and CLOCKS_PER_SEC for clock() function.
Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz)
returns the clock ticks per second.
Process.clock_getres(:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz)
returns CLOCKS_PER_SEC.
p Process.clock_getres(Process::CLOCK_MONOTONIC) #=> 1.0e-09