##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: November 2016 # Modified: 2016-12-01/01:04-0500 ##+ # # fork.icn, demonstrate process forking # procedure main() local sharedvar := 42 # parent process i := fork() | stop("fork() fail") if i < 0 then stop("fork fail with ", i) # at this point, two nearly identical processes are running # each will have a unique pid and "i" result # the variable "sharedvar" will be a copy. Both processes will # see it as 42 at first. Child divides to 21, parent doubles to 84 if i = 0 then { write("child process: ", right(i, 6), ", ", sharedvar) sharedvar /:= 2 } else { write("parent process: ", right(i, 5), ", ", sharedvar) sharedvar *:= 2 } # both processes will display this line and then end write("sharedvar for ", if i = 0 then "child " else "parent", " process is now: ", sharedvar) end