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"