別のキーワード
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - Status (11)
- logger (11)
- spawn (44)
- timeout (19)
検索結果
先頭5件
-
Kernel
. # `(command) -> String (18162.0) -
command を外部コマンドとして実行し、その標準出力を文字列として 返します。このメソッドは `command` の形式で呼ばれます。
...command を外部コマンドとして実行し、その標準出力を文字列として
返します。このメソッドは `command` の形式で呼ばれます。
引数 command に対しダブルクォートで囲まれた文字列と同様の解釈と式展開を行った後、
コマンド......必要がなく、単にコマンドを実行したいだけなら
Kernel.#system を使います。特に端末を制御するコマンドでは
`command` は失敗するかもしれません。
d:spec/literal#command も参照。
@param command コマンドとして実行する引数です。そ......Errno::EXXX コマンドを実行できないときや失敗した場合に発生します。
//emlist[例][ruby]{
puts `ruby -v` #=> ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
puts $?.inspect #=> #<Process::Status: pid=3580,exited(0)>
//}
@see Kernel.#system,Kernel.#exec,Kernel.#spawn... -
Kernel
. # spawn(env , program , *args , options={}) -> Integer (175.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, :pgroup => true)
# 整数を渡すとそのグループに所属します。
pid = spawn(command, :pgroup => 10)
//}
「:rlimit_core」「:rlimit_cpu」などで、resource limit を指定します。
詳しくは Process.#setrli... -
Kernel
. # spawn(program , *args) -> Integer (175.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, :pgroup => true)
# 整数を渡すとそのグループに所属します。
pid = spawn(command, :pgroup => 10)
//}
「:rlimit_core」「:rlimit_cpu」などで、resource limit を指定します。
詳しくは Process.#setrli... -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (96.0) -
1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))
...Proc.new {|a,b,c| p [a,b,c]}.call(1,2)
=> -:1: wrong # of arguments (2 for 3) (ArgumentError)
from -:1:in `call'
from -:1
ruby 1.6.8 (2002-12-24) [i586-linux]
=> ruby 1.8.0 (2003-06-21) [i586-linux......[1, 2, nil]
Proc.new { break }.call
=> ruby 1.6.8 (2002-12-24) [i586-linux]
=> -:1:in `call': break from proc-closure (LocalJumpError)
from -:1
ruby 1.8.0 (2003-06-21) [i586-linux]
* lam......ss.exit>)) [new]
追加。関数 abort, exit と同じ。
: ((<Process/Process.waitall>)) [new]
追加
: ((<Process::Status#pid|Process::Status/pid>)) [new]
追加
=== Range
: ((<Range#step|Range/step>)) [new]
追加。step ごとの要素で繰り返します。
: ((<Ran... -
Process
:: Status (96.0) -
プロセスの終了ステータスを表すクラスです。 メソッド Process.#wait2 などの返り値として使われます。
...xit }
Process.wait
case
when $?.signaled?
p "child #{$?.pid} was killed by signal #{$?.termsig}"
if $?.coredump? # システムがこのステータスをサポートしてなければ常にfalse
p "child #{$?.pid} dumped core."
end
when $?.stopped?
# 実際には Pro......cess.wait を使用しているので、ここに来ることはない
p "child #{$?.pid} was stopped by signal #{$?.stopsig}"
when $?.exited?
p "child #{$?.pid} exited normally. status=#{$?.exitstatus}"
else
p "unknown status %#x" % $?.to_i
end
SIGCHLD を trap する例
trap(......つための sleep
Process.kill :CONT, pid2
Process.kill :TERM, pid2
loop { sleep } # SIGCHLD を待つための sleep
rescue Errno::ECHILD
puts "done"
end
=> 12964
12965
interrupted by signal 17 at -:27:in `sleep'
child 12965 was stopped by si... -
Kernel
. # spawn(command , options={}) -> Integer (35.0) -
引数を外部コマンドとして実行しますが、生成した 子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
...ロセスIDを返します。
=== 引数の解釈
この形式では command が shell のメタ文字
//emlist{
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
//}
を含む場合、shell 経由で実行されます。
そうでなければインタプリタから直接実行されます。
@param comm... -
Kernel
. # spawn(env , command , options={}) -> Integer (35.0) -
引数を外部コマンドとして実行しますが、生成した 子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
...ロセスIDを返します。
=== 引数の解釈
この形式では command が shell のメタ文字
//emlist{
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
//}
を含む場合、shell 経由で実行されます。
そうでなければインタプリタから直接実行されます。
@param comm... -
Timeout
. # timeout(sec , exception _ class = nil) {|i| . . . } -> object (30.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...ang.org", [], 2, "210.251.121.214"]
0.689331
/usr/local/lib/ruby/1.6/timeout.rb:37: execution expired (TimeoutError)
from -:6:in `timeout'
from -:6
# gethostbyname が0.1秒かからない場合は例外が発生しないので
# その場合は、t に小さい......(0755, "loop.sh")
t = 10 # 10 秒でタイムアウト
begin
pid = nil
com = nil
Timeout.timeout(t) {
# system だととまらない
# system("./loop.sh")
com = IO.popen("./loop.sh")
pid = com.pid
while line = com.gets
print line
end
}......rescue Timeout::Error => err
puts "timeout: shell execution."
Process.kill('SIGINT', pid)
printf "[result]\t%s", com.read
com.close unless com.nil?
end
#止まっているか確認する。
#system("ps au")... -
Timeout
. # timeout(sec , exception _ class , message) {|i| . . . } -> object (30.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...ang.org", [], 2, "210.251.121.214"]
0.689331
/usr/local/lib/ruby/1.6/timeout.rb:37: execution expired (TimeoutError)
from -:6:in `timeout'
from -:6
# gethostbyname が0.1秒かからない場合は例外が発生しないので
# その場合は、t に小さい......(0755, "loop.sh")
t = 10 # 10 秒でタイムアウト
begin
pid = nil
com = nil
Timeout.timeout(t) {
# system だととまらない
# system("./loop.sh")
com = IO.popen("./loop.sh")
pid = com.pid
while line = com.gets
print line
end
}......rescue Timeout::Error => err
puts "timeout: shell execution."
Process.kill('SIGINT', pid)
printf "[result]\t%s", com.read
com.close unless com.nil?
end
#止まっているか確認する。
#system("ps au")... -
logger (12.0)
-
ログを記録するためのライブラリです。
...2:53.649222 #11601] FATAL -- : No such file or directory @ rb_sysopen - a_non_existent_file (Errno::ENOENT)
logger_sample.rb:12:in `foreach'
logger_sample.rb:12:in `<main>'
これは log.level が Logger::WARN になっているためです。WARN、
ERROR、FATALログのみが記録の対象......フォルトのフォー
マットとその場合のログの例は以下のようになります。
フォーマット:
SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
例:
I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
Logger#datetime_format= を用いてログ...