OILS / soil / timeout-test.sh View on Github | oilshell.org

50 lines, 28 significant
1#!/usr/bin/env bash
2#
3# Figuring out how GNU timeout works.
4#
5# Usage:
6# soil/timeout-test.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12source test/common.sh
13
14test-simple() {
15 time timeout 0.1 sleep 10
16}
17
18one() {
19 echo "- sleep 0.$1 in pid $$"
20 sleep 0.$1
21}
22
23many() {
24 seq 5 8 | xargs -n 1 -P 3 $0 one
25}
26
27test-xargs() {
28 local pid=$$
29 set +o errexit
30
31 # This shows the full process tree
32 $0 many &
33
34 #timeout 0.1 $0 many &
35
36 sleep 0.1
37 pstree --ascii -p $pid
38
39 echo 'Any sleep processes alive?'
40 pgrep sleep
41
42 wait
43 echo status=$?
44}
45
46all() {
47 run-test-funcs
48}
49
50"$@"