種類
- 特異メソッド (154)
- モジュール関数 (110)
- インスタンスメソッド (22)
- クラス (11)
ライブラリ
- ビルトイン (297)
検索結果
先頭5件
-
Kernel
. # fork -> Integer | nil (26166.0) -
fork(2) システムコールを使ってプロセスの複製を作 ります。親プロセスでは子プロセスのプロセスIDを、子プロセスでは nil を返します。ブロックを指定して呼び出した場合には、生成し た子プロセスでブロックを評価します。
...
fork(2) システムコールを使ってプロセスの複製を作
ります。親プロセスでは子プロセスのプロセスIDを、子プロセスでは
nil を返します。ブロックを指定して呼び出した場合には、生成し
た子プロセスでブロックを評価しま......す。
fork 前に STDOUT と STDERR を IO#flush します。
@raise NotImplementedError 実行環境がこのメソッドに対応していないとき発生します。
//emlist[ブロックを指定しなかった場合][ruby]{
if child_pid = fork
puts "parent process. pid: #{Process.pid},......て終了。
Process.waitpid(child_pid)
else
puts "child process. pid: #{Process.pid}"
# => child process. pid: 81329
# 子プロセスでの処理
sleep(1)
end
//}
//emlist[ブロックを指定した場合][ruby]{
child_pid = fork do
puts "child process. pid: #{Process.pid}"
# => c... -
Kernel
. # fork { . . . } -> Integer | nil (26166.0) -
fork(2) システムコールを使ってプロセスの複製を作 ります。親プロセスでは子プロセスのプロセスIDを、子プロセスでは nil を返します。ブロックを指定して呼び出した場合には、生成し た子プロセスでブロックを評価します。
...
fork(2) システムコールを使ってプロセスの複製を作
ります。親プロセスでは子プロセスのプロセスIDを、子プロセスでは
nil を返します。ブロックを指定して呼び出した場合には、生成し
た子プロセスでブロックを評価しま......す。
fork 前に STDOUT と STDERR を IO#flush します。
@raise NotImplementedError 実行環境がこのメソッドに対応していないとき発生します。
//emlist[ブロックを指定しなかった場合][ruby]{
if child_pid = fork
puts "parent process. pid: #{Process.pid},......て終了。
Process.waitpid(child_pid)
else
puts "child process. pid: #{Process.pid}"
# => child process. pid: 81329
# 子プロセスでの処理
sleep(1)
end
//}
//emlist[ブロックを指定した場合][ruby]{
child_pid = fork do
puts "child process. pid: #{Process.pid}"
# => c... -
Process
:: Status (8054.0) -
プロセスの終了ステータスを表すクラスです。 メソッド Process.#wait2 などの返り値として使われます。
...スを表すクラスです。
メソッド Process.#wait2 などの返り値として使われます。
=== 使用例
wait を使用した例
fork { exit }
Process.wait
case
when $?.signaled?
p "child #{$?.pid} was killed by signal #{$?.termsig}"
if $?.coredump? # システム......exited normally. status=#{$?.exitstatus}"
else
p "unknown status %#x" % $?.to_i
end
SIGCHLD を trap する例
trap(:SIGCHLD) {|sig|
puts "interrupted by signal #{sig} at #{caller[1]}"
# 複数の子プロセスの終了に対して1つの SIGCHLD しか届かない
# 場......signaled?
puts " child #{$?.pid} was killed by signal #{$?.termsig}"
if $?.coredump?
puts " child #{$?.pid} dumped core."
end
when $?.stopped?
puts " child #{$?.pid} was stopped by signal #{$?.stopsig}"
when $?.exited?
puts " chil... -
Object
# respond _ to?(name , include _ all = false) -> bool (8048.0) -
オブジェクトがメソッド name を持つとき真を返します。
...ッド name を持つというのは、
オブジェクトが メソッド name に応答できることをいいます。
Windows での Process.fork や GNU/Linux での File.lchmod の
ような NotImplementedError が発生する場合は false を返します。
※ NotImplementedError が発......D.new]
list.each{|it| puts it.hello if it.respond_to?(:hello)}
#=> Bonjour
list.each{|it| it.instance_eval("puts hello if it.respond_to?(:hello, true)")}
#=> Bonjour
# Guten Tag
module Template
def main
start
template_method
finish
end
def start
puts "start"
end
def......mentedError.new
end
def finish
puts "finish"
end
end
class ImplTemplateMethod
include Template
def template_method
"implement template_method"
end
end
class NotImplTemplateMethod
include Template
# not implement template_method
end
puts ImplTemplateMethod.new.respond_to?... -
File
# flock(operation) -> 0 | false (8036.0) -
ファイルをロックします。
...File.open("/tmp/foo", "w")
f.flock(File::LOCK_EX)
puts "locked by process1"
fork {
f = File.open("/tmp/foo", "r")
f.flock(File::LOCK_SH)
puts "locked by process2"
sleep 5
puts "unlocked by process2"
}
sleep 5
f.flock(File::LOCK_UN)
puts "unlocked by process1"
sleep 1 # <- 子プロセ......スが確実に先にロックするための sleep
f.flock(File::LOCK_EX)
puts "re-locked by process1"
# => locked by process1
# unlocked by process1
# locked by process2
# unlocked by process2
# re-locked by process1
//}... -
IO
. popen("-" , mode = "r" , opt={}) -> IO (8036.0) -
第一引数に文字列 "-" が指定された時、fork(2) を 行い子プロセスの標準入出力との間にパイプラインを確立します。 親プロセスでは IO オブジェクトを返し、子プロセスでは nil を返します。
...定された時、fork(2) を
行い子プロセスの標準入出力との間にパイプラインを確立します。
親プロセスでは IO オブジェクトを返し、子プロセスでは
nil を返します。
io = IO.popen("-", "r+")
if io # parent
io.puts "foo"
p io.gets......引数にブロックを実行し終了します。
p IO.popen("-", "r+") {|io|
if io # parent
io.puts "foo"
io.gets
else # child
s = gets
puts "child output: " + s
end
}
# => "child output: foo\n"
opt ではエンコーディングの設定やプ... -
IO
. popen("-" , mode = "r" , opt={}) {|io| . . . } -> object (8036.0) -
第一引数に文字列 "-" が指定された時、fork(2) を 行い子プロセスの標準入出力との間にパイプラインを確立します。 親プロセスでは IO オブジェクトを返し、子プロセスでは nil を返します。
...定された時、fork(2) を
行い子プロセスの標準入出力との間にパイプラインを確立します。
親プロセスでは IO オブジェクトを返し、子プロセスでは
nil を返します。
io = IO.popen("-", "r+")
if io # parent
io.puts "foo"
p io.gets......引数にブロックを実行し終了します。
p IO.popen("-", "r+") {|io|
if io # parent
io.puts "foo"
io.gets
else # child
s = gets
puts "child output: " + s
end
}
# => "child output: foo\n"
opt ではエンコーディングの設定やプ... -
IO
. popen(env , "-" , mode = "r" , opt={}) -> IO (8036.0) -
第一引数に文字列 "-" が指定された時、fork(2) を 行い子プロセスの標準入出力との間にパイプラインを確立します。 親プロセスでは IO オブジェクトを返し、子プロセスでは nil を返します。
...定された時、fork(2) を
行い子プロセスの標準入出力との間にパイプラインを確立します。
親プロセスでは IO オブジェクトを返し、子プロセスでは
nil を返します。
io = IO.popen("-", "r+")
if io # parent
io.puts "foo"
p io.gets......引数にブロックを実行し終了します。
p IO.popen("-", "r+") {|io|
if io # parent
io.puts "foo"
io.gets
else # child
s = gets
puts "child output: " + s
end
}
# => "child output: foo\n"
opt ではエンコーディングの設定やプ... -
IO
. popen(env , "-" , mode = "r" , opt={}) {|io| . . . } -> object (8036.0) -
第一引数に文字列 "-" が指定された時、fork(2) を 行い子プロセスの標準入出力との間にパイプラインを確立します。 親プロセスでは IO オブジェクトを返し、子プロセスでは nil を返します。
...定された時、fork(2) を
行い子プロセスの標準入出力との間にパイプラインを確立します。
親プロセスでは IO オブジェクトを返し、子プロセスでは
nil を返します。
io = IO.popen("-", "r+")
if io # parent
io.puts "foo"
p io.gets......引数にブロックを実行し終了します。
p IO.popen("-", "r+") {|io|
if io # parent
io.puts "foo"
io.gets
else # child
s = gets
puts "child output: " + s
end
}
# => "child output: foo\n"
opt ではエンコーディングの設定やプ... -
Kernel
. # exit!(status = false) -> () (8036.0) -
Rubyプログラムの実行を即座に終了します。 status として整数が与えられた場合、その値を Ruby コマンドの終了ステータスとします。 デフォルトの終了ステータスは 1 です。
...Kernel.#fork の後、子プロセスを終了させる時などに用
いられます。
@param status 終了ステータスを整数か true または false で与えます。
//emlist[例][ruby]{
STDOUT.sync = true #表示前に終了しないようにする
puts 'start'
begin
puts 'start1.........'
exit!
ensure
puts 'end1...' #実行されない
end
puts 'end' #実行されない
#=> start
# start1...
#終了ステータス:1
//}
@see Kernel.#exit,Kernel.#abort,Kernel.#at_exit,Kernel.#fork...