忍者ブログ

開発や調査の結果を断片的に残す目的のブログ

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

1.非同期実行(バックグラウンド実行)
  コマンドの後に”&”を付与する。

2.非同期実行時のプロセスIDを取得する
  "$!"で取得する。

3. 実行後の結果(リターンコード)取得
  非同期実行を行った処理の終了を待った後に、"$?"で取得。
  wait プロセスID
  $?


#exec.sh
#!/usr/bin/sh

sh test.sh aa &
test1pid=$!
sh test.sh bb &
test2pid=$!
sh test.sh cc &
test3pid=$!

wait $test1pid
echo $?
wait $test2pid
echo $?
wait $test3pid
echo $?

echo end

exit 0

#test.sh
#!/usr/bin/sh

a=1
while [ $a -lt 1000 ]
do
    if [ $a -eq 250 ]; then
        echo "a = $1: $a"
    elif [ $a -eq 500 ]; then
        echo "a = $1: $a"
    elif [ $a -eq 750 ]; then
        echo "a = $1: $a"
    fi
    a=`expr $a + 1`
done

    if [ $1 = "aa" ]; then
        exit 1
    elif [ $1 = "bb" ]; then
        exit 2
    elif [ $1 = "cc" ]; then
        exit 3
    fi
PR

◎ Post your Comment
Name
Title
E-mail
URL
Comment
Pass   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
◎ この記事へのトラックバック
Trackback URL
◎ カレンダー
04 2025/05 06
S M T W T F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
◎ 最新トラックバック
◎ プロフィール
HN:
Kazoo
性別:
非公開
職業:
プログラマ
趣味:
プログラム
◎ ブログ内検索
Script: Ninja Blog 
Design by: タイムカプセル
忍者ブログ 
[PR]