Perpetual REBOL CMD Process UN*X
[1/1] from: phil::hayes::cnutarch::net at: 10-Oct-2001 8:34
This script always ensures that the 'forked' child process is always
running:
######
REBOL[]
clib: make library! %/lib/libc.so.6
getpid: make routine!
return: [ integer! ]
] clib "getpid"
fork: make routine!
return: [ integer! ]
] clib "fork"
perror: make routine!
str [ string! ]
return: [ long ]
] clib "perror"
waitpid: make routine! [
pid [ integer! ]
status [ integer! ]
options [ integer! ]
return: [ integer! ]
] clib "waitpid"
forever [
childPid: fork
either equal? 0 childPid [
; Child
wait 1
print [ "[" getpid "] Child start" now/time ]
; perform logic i.e.
free clib
quit
] [
; Parent
print [ "[" getpid "] Parent Waitpid" now/time ]
rc: reform [ waitpid childPid 0 0 ]
if equal? -1 rc
perror "function [waitpid]"
free clib
quit
]
]
]
free clib
quit 0
####
Phil