1 | # fork and forkwait
|
2 |
|
3 | #### fork and forkwait usage errors
|
4 | shopt --set oil:upgrade
|
5 | shopt --unset errexit
|
6 |
|
7 | fork
|
8 | echo status=$?
|
9 |
|
10 | fork extra
|
11 | echo status=$?
|
12 |
|
13 | fork extra {
|
14 | echo hi
|
15 | }
|
16 | echo status=$?
|
17 |
|
18 | #
|
19 |
|
20 | forkwait
|
21 | echo status=$?
|
22 |
|
23 | forkwait extra
|
24 | echo status=$?
|
25 |
|
26 | forkwait extra {
|
27 | echo hi
|
28 | }
|
29 | echo status=$?
|
30 |
|
31 | ## STDOUT:
|
32 | status=2
|
33 | status=2
|
34 | status=2
|
35 | status=2
|
36 | status=2
|
37 | status=2
|
38 | ## END
|
39 |
|
40 | #### forkwait
|
41 | shopt --set oil:upgrade
|
42 | shopt --unset errexit
|
43 |
|
44 | old=$PWD
|
45 |
|
46 | forkwait {
|
47 | cd /
|
48 | echo hi
|
49 | exit 42
|
50 | }
|
51 | echo status=$?
|
52 | if test "$old" = "$PWD"; then
|
53 | echo ok
|
54 | fi
|
55 | ## STDOUT:
|
56 | hi
|
57 | status=42
|
58 | ok
|
59 | ## END
|
60 |
|
61 | #### fork
|
62 | shopt --set oil:upgrade
|
63 | shopt --unset errexit
|
64 |
|
65 | old=$PWD
|
66 |
|
67 | fork {
|
68 | cd /
|
69 | echo hi
|
70 | sleep 0.01
|
71 | exit 42
|
72 | }
|
73 | #echo status=$? race condition
|
74 |
|
75 | wait -n
|
76 | echo status=$?
|
77 |
|
78 | if test "$old" = "$PWD"; then
|
79 | echo ok
|
80 | fi
|
81 | ## STDOUT:
|
82 | hi
|
83 | status=42
|
84 | ok
|
85 | ## END
|