spark-supervisor
Process supervisor and health monitor for sovereign daemons
Brought by drakestapleton
spark-supervisor / tests / load.om
| 1 | om2 |
| 2 | note Test-only resource child: memory growth touches every page, fork growth retains children. |
| 3 | global memory uchar * |
| 4 | text memMode "memory" |
| 5 | text forkMode "fork" |
| 6 | text held "FORK_HELD\n" |
| 7 | text noHold "FORK_NOT_HELD\n" |
| 8 | text survived "MEMORY_SURVIVED\n" |
| 9 | fn equal a view uchar 64 n ulong s view uchar * to bool |
| 10 | if ne n len s |
| 11 | ret false |
| 12 | end |
| 13 | for j ulong n |
| 14 | if ne get a j get s j |
| 15 | ret false |
| 16 | end |
| 17 | end |
| 18 | ret true |
| 19 | end |
| 20 | fn main to int |
| 21 | a = new uchar 64 0 |
| 22 | if lt argcnt 2 |
| 23 | ret 2 |
| 24 | end |
| 25 | r = argread 1 a 0 len a |
| 26 | if lt r 0 |
| 27 | ret 2 |
| 28 | end |
| 29 | if equal a ulong r memMode |
| 30 | r = argread 2 a 0 len a |
| 31 | if le r 0 |
| 32 | ret 2 |
| 33 | end |
| 34 | n = ulong 0 |
| 35 | for j ulong ulong r |
| 36 | b = get a j |
| 37 | if or lt b 48 gt b 57 |
| 38 | ret 2 |
| 39 | end |
| 40 | n = add mul n 10 ulong sub b 48 |
| 41 | end |
| 42 | r = enlarge memory n |
| 43 | if lt r 0 |
| 44 | ret 3 |
| 45 | end |
| 46 | position = ulong 0 |
| 47 | while lt position n bound 9223372036854775807 |
| 48 | put memory position 1 |
| 49 | position = add position 4096 |
| 50 | end |
| 51 | if gt n 0 |
| 52 | put memory sub n 1 1 |
| 53 | end |
| 54 | w = write 1 survived 0 len survived |
| 55 | ret 0 |
| 56 | end |
| 57 | if equal a ulong r forkMode |
| 58 | for j ulong 128 |
| 59 | pid = fork |
| 60 | if lt pid 0 |
| 61 | if gt j 7 |
| 62 | w = write 1 noHold 0 len noHold |
| 63 | ret 1 |
| 64 | end |
| 65 | w = write 1 held 0 len held |
| 66 | ret 0 |
| 67 | end |
| 68 | if eq pid 0 |
| 69 | s = sleepns 30000000000 |
| 70 | exit 0 |
| 71 | end |
| 72 | end |
| 73 | w = write 1 noHold 0 len noHold |
| 74 | ret 1 |
| 75 | end |
| 76 | ret 2 |
| 77 | end |