From a35331f35df7a1c8d7aec8ba2abab5f35dd864e2 Mon Sep 17 00:00:00 2001 From: JamesonHuang Date: Thu, 2 Jul 2015 22:53:31 +0800 Subject: [PATCH] test sh run in background --- 1_3.test_code/sh_test/background_exec.sh | 15 +++++++++++++++ 1_3.test_code/sh_test/fork_shell.sh | 3 +++ 1_3.test_code/sh_test/random.sh | 14 ++++++++++++++ 1_3.test_code/sh_test/test.sh | 3 +++ 4 files changed, 35 insertions(+) create mode 100755 1_3.test_code/sh_test/background_exec.sh create mode 100755 1_3.test_code/sh_test/fork_shell.sh create mode 100755 1_3.test_code/sh_test/random.sh create mode 100755 1_3.test_code/sh_test/test.sh diff --git a/1_3.test_code/sh_test/background_exec.sh b/1_3.test_code/sh_test/background_exec.sh new file mode 100755 index 0000000..085528c --- /dev/null +++ b/1_3.test_code/sh_test/background_exec.sh @@ -0,0 +1,15 @@ +#!/bin/bash +function fileNum(){ +while true +do + echo "sleep background" + sleep 5 +done +} +fileNum & +while true +do + echo "sleep foreground" + sleep 1 +done + diff --git a/1_3.test_code/sh_test/fork_shell.sh b/1_3.test_code/sh_test/fork_shell.sh new file mode 100755 index 0000000..dd0773f --- /dev/null +++ b/1_3.test_code/sh_test/fork_shell.sh @@ -0,0 +1,3 @@ +#!/bin/bash +sh -c "exec ./test.sh" +echo abc diff --git a/1_3.test_code/sh_test/random.sh b/1_3.test_code/sh_test/random.sh new file mode 100755 index 0000000..889c84d --- /dev/null +++ b/1_3.test_code/sh_test/random.sh @@ -0,0 +1,14 @@ +#!/bin/sh +random_num=$(date +%s%N) +echo $random_num + +#指定范围随机数 +rand(){ + min=$1 + max=$(($2-$min+1)) + num=$(date +%s%N) + echo $(($num%$max+$min)) +} +random_num2=$(rand 1 3) +sleep ${random_num2} +echo $random_num2 diff --git a/1_3.test_code/sh_test/test.sh b/1_3.test_code/sh_test/test.sh new file mode 100755 index 0000000..e05cf1d --- /dev/null +++ b/1_3.test_code/sh_test/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +ps +echo "hello world"