種類
- モジュール関数 (132)
- インスタンスメソッド (12)
クラス
- IO (12)
キーワード
- fork (24)
- pipeline (12)
-
pipeline
_ r (24) -
pipeline
_ start (24) - spawn (48)
検索結果
先頭5件
-
IO
# pid -> Integer | nil (18149.0) -
自身が IO.popen で作られたIOポートなら、子プロセスのプロセス ID を 返します。それ以外は nil を返します。
...close されている場合に発生します。
//emlist[例][ruby]{
IO.popen("-") do |pipe|
if pipe
$stderr.puts "In parent, child pid is #{pipe.pid}" # => In parent, child pid is 16013
else
$stderr.puts "In child, pid is #{$$}" # => In child, pid is 16013
end
end
//}... -
Open3
. # pipeline(*cmds) -> [Process :: Status] (6118.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。
...sr/share/man/man1/ruby.1.gz"
p Open3.pipeline(["zcat", fname], "nroff -man", "less")
#=> [#<Process::Status: pid 11817 exit 0>,
# #<Process::Status: pid 11820 exit 0>,
# #<Process::Status: pid 11828 exit 0>]
例2:
require "open3"
Open3.pipeline([{"LANG"=>"C"}, "env"], ["grep", "... -
Open3
. # pipeline _ r(*cmds) -> [IO , [Thread]] (6112.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最後の コマンドの標準出力を受けとる事ができます。
...します。
例:
require "open3"
Open3.pipeline_r("yes", "head -10") {|r, ts|
p r.read #=> "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n"
p ts[0].value #=> #<Process::Status: pid 24910 SIGPIPE (signal 13)>
p ts[1].value #=> #<Process::Status: pid 24913 exit 0>
}
@see Open3.#popen3... -
Open3
. # pipeline _ r(*cmds) {|last _ stdout , wait _ thrs| . . . } -> () (6112.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。最後の コマンドの標準出力を受けとる事ができます。
...します。
例:
require "open3"
Open3.pipeline_r("yes", "head -10") {|r, ts|
p r.read #=> "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n"
p ts[0].value #=> #<Process::Status: pid 24910 SIGPIPE (signal 13)>
p ts[1].value #=> #<Process::Status: pid 24913 exit 0>
}
@see Open3.#popen3... -
Open3
. # pipeline _ start(*cmds) -> [Thread] (6112.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。
...ッ
ドの配列を返します。
例:
require "open3"
# xeyesを10秒だけ実行する。
Open3.pipeline_start("xeyes") {|ts|
sleep 10
t = ts[0]
Process.kill("TERM", t.pid)
p t.value #=> #<Process::Status: pid 911 SIGTERM (signal 15)>
}
@see Open3.#popen3... -
Open3
. # pipeline _ start(*cmds) {|wait _ thrs| . . . } -> () (6112.0) -
指定したコマンドのリストをパイプで繋いで順番に実行します。
...ッ
ドの配列を返します。
例:
require "open3"
# xeyesを10秒だけ実行する。
Open3.pipeline_start("xeyes") {|ts|
sleep 10
t = ts[0]
Process.kill("TERM", t.pid)
p t.value #=> #<Process::Status: pid 911 SIGTERM (signal 15)>
}
@see Open3.#popen3... -
Kernel
. # spawn(env , program , *args , options={}) -> Integer (186.0) -
引数を外部コマンドとして実行しますが、生成した 子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
...数が削除(unsetenv(3))されます。
//emlist[例][ruby]{
# FOO を BAR にして BAZ を削除する
pid = spawn({"FOO"=>"BAR", "BAZ"=>nil}, command)
//}
親プロセスは Process.#waitpid で子プロセスの終了を待ち合わせるか
もしくは Process.#detach で子プロセスを......定したもの以外の環境変数を
クリアします。
//emlist[][ruby]{
# すべての環境変数をクリア
pid = spawn(command, :unsetenv_others=>true)
# FOO だけ
pid = spawn({"FOO"=>"BAR"}, command, :unsetenv_others=>true)
//}
「:pgroup」でプロセスグループを指定でき......{
pid = spawn(command, :close_others=>true) # close 3,4,5,... (default)
pid = spawn(command, :close_others=>false) # don't close 3,4,5,...
//}
これを利用して spawn を IO.popen のように使うことができます。
//emlist[][ruby]{
# similar to r = IO.popen(command)
r, w = IO.pipe
pid......{
pid = spawn(command, :close_others=>true) # close 3,4,5,...
pid = spawn(command, :close_others=>false) # don't close 3,4,5,... (default)
//}
これを利用して spawn を IO.popen のように使うことができます。
//emlist[][ruby]{
# similar to r = IO.popen(command)
r, w = IO.pipe
pid... -
Kernel
. # spawn(program , *args) -> Integer (186.0) -
引数を外部コマンドとして実行しますが、生成した 子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
...数が削除(unsetenv(3))されます。
//emlist[例][ruby]{
# FOO を BAR にして BAZ を削除する
pid = spawn({"FOO"=>"BAR", "BAZ"=>nil}, command)
//}
親プロセスは Process.#waitpid で子プロセスの終了を待ち合わせるか
もしくは Process.#detach で子プロセスを......定したもの以外の環境変数を
クリアします。
//emlist[][ruby]{
# すべての環境変数をクリア
pid = spawn(command, :unsetenv_others=>true)
# FOO だけ
pid = spawn({"FOO"=>"BAR"}, command, :unsetenv_others=>true)
//}
「:pgroup」でプロセスグループを指定でき......{
pid = spawn(command, :close_others=>true) # close 3,4,5,... (default)
pid = spawn(command, :close_others=>false) # don't close 3,4,5,...
//}
これを利用して spawn を IO.popen のように使うことができます。
//emlist[][ruby]{
# similar to r = IO.popen(command)
r, w = IO.pipe
pid......{
pid = spawn(command, :close_others=>true) # close 3,4,5,...
pid = spawn(command, :close_others=>false) # don't close 3,4,5,... (default)
//}
これを利用して spawn を IO.popen のように使うことができます。
//emlist[][ruby]{
# similar to r = IO.popen(command)
r, w = IO.pipe
pid... -
Kernel
. # fork -> Integer | nil (138.0) -
fork(2) システムコールを使ってプロセスの複製を作 ります。親プロセスでは子プロセスのプロセスIDを、子プロセスでは nil を返します。ブロックを指定して呼び出した場合には、生成し た子プロセスでブロックを評価します。
...pid = fork
puts "parent process. pid: #{Process.pid}, child pid: #{child_pid}"
# => parent process. pid: 81060, child pid: 81329
# 親プロセスでの処理
# ...
# 子プロセスの終了を待って終了。
Process.waitpid(child_pid)
else
puts "child process. pid: #{Process.pid......rocess. pid: 81329
# 子プロセスでの処理
sleep(1)
end
//}
//emlist[ブロックを指定した場合][ruby]{
child_pid = fork do
puts "child process. pid: #{Process.pid}"
# => child process. pid: 79602
# 子プロセスでの処理
sleep(1)
end
puts "parent process. pid: #{Pr......ocess.pid}, child pid: #{child_pid}"
# => parent process. pid: 79055, child pid: 79602
# 親プロセスでの処理
# ...
# 子プロセスの終了を待って終了。
Process.waitpid(child_pid)
//}
@see IO.popen,IO.pipe,Kernel.#at_exit,Kernel.#exit!, fork(2)...