Wait

del.icio.us del.icio.us
Digg Digg
Furl Furl
Reddit Reddit
Rojo Rojo
Add to OnlyWire

waitは、バックグラウンドプロセスの実行が終了するまで停止するコマンドである。

目次

使用法

wait [n]

nが現在実行しているバックグラウンドプロセス(ジョブ)のPIDまたはジョブIDである。nが与えられていない場合、このコマンドはシェルが把握している全てのジョブが終了するまで停止する。

通常、waitは最後に終了したジョブの終了ステータスを返す。nに存在しないジョブやゼロを指定し、待つべきジョブが存在しない場合は、127を返すことがある。

waitは、現在のシェル実行環境のジョブテーブルを参照する必要があるため、通常はシェルビルトインとして実装されている。

このコマンドは、スクリプトの一部を並行で実行し、後ろの部分が前の部分の完了に依存するようなバリアを実装するときに役に立つ。

以下の(若干不自然な)例は、inoaという名前のホストからsrc/ディレクトリをrsyncで取り込み、同時にこのプログラムが依存するライブラリを更新し、これらを組み合わせてビルドを実行する。

#!/bin/bash
 
# Parallel update script which makes use of the wait command
 
# Update local copy
rsync iona:src/ . &
# Upgrade required libraries, or exit indicating failure if make failed for some reason
make -C lib || exit 1
 
# Wait for rsync to terminate (may have already happened) and finish the job, unless rsync failed
wait && make

関連項目

外部リンク

This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.


Giant Panda

Mercedes Car
James Bond Guide
This site monitored by SitePinger.net