summaryrefslogtreecommitdiffhomepage
path: root/tests/zos/shareas.sh
blob: e63557260d1b66479788712ad4597d52b4a21611 (plain)
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
32
33
34
35
36
37
38
39
40
41
# z/OS: with _BPX_SHAREAS=YES a spawned child shares the shell's address
# space; with NO it gets its own.  xasid is the ps(1) address space id.
# Look at a live /bin/sleep rather than asking /bin/sh to run ps: /bin/sh
# has the sticky bit on z/OS, and spawn() is required to give such a file
# its own address space regardless of _BPX_SHAREAS.
# spawn() returns before the child is visible to ps, so look for it a few
# times; a system that never shows it cannot be measured here at all.
asid_of() {
    tries=0
    while [ "$tries" -lt 5 ]; do
        a=$(ps -o xasid= -p "$1" 2>/dev/null | tr -d ' ')
        [ -n "$a" ] && {
            echo "$a"
            return
        }
        tries=$((tries + 1))
        /bin/sleep 1
    done
}
me=$(asid_of $$)
[ -n "$me" ] || exit 77
_BPX_SHAREAS=YES; export _BPX_SHAREAS
/bin/sleep 3 & child=$!
shared=$(asid_of "$child")
wait "$child"
[ -n "$shared" ] || exit 77
[ "$shared" = "$me" ] && echo "YES: same address space" || echo "YES: different ($me $shared)"
_BPX_SHAREAS=NO
/bin/sleep 3 & child=$!
own=$(asid_of "$child")
wait "$child"
[ -n "$own" ] || exit 77
[ "$own" != "$me" ] && echo "NO: own address space" || echo "NO: shared"
# A subshell is a fork(): always its own address space.
child=$(
    /bin/sleep 3 & p=$!
    asid_of "$p"
    wait "$p"
)
[ -n "$child" ] || exit 77
[ "$child" != "$me" ] && echo "fork: own address space" || echo "fork: shared"