Fork: Difference between revisions

Content added Content deleted
Line 472: Line 472:


=={{header|J}}==
=={{header|J}}==
This example works by calling fork in a shared object library of Ubuntu 14.04.1 LTS . Our Fork adverb consumes a gerund consisting of tied verbs to evaluate in the appropriate parent or child process. A conjunctive form parent_verb Fork child_verb would also be reasonable.
This example works by calling fork in a shared object library of Ubuntu 14.04.1 LTS . The verb given to adverb Fork evaluates in the child process.
<lang J>
<lang J>
load'dll'
load'dll'
Fork =: @.(0='/lib/x86_64-linux-gnu/libc-2.19.so __fork > x' cd [: i. 0:)
Fork =: (('Error'"_)`('Parent'"_)`)(@.([: >: [: * '/lib/x86_64-linux-gnu/libc-2.19.so __fork > x' cd [: i. 0&[))</lang>
The child process explicitly exits remaining as a zombie until the parent terminates.
</lang>
The child process explicitly exits, with the child remaining as a zombie process until the parent terminates.
<pre>
<pre>
NB. interactive session demonstrating Fork
NB. interactive session demonstrating Fork
Line 483: Line 482:
SLEEP =: 3
SLEEP =: 3
sleep =: SLEEP Time
sleep =: SLEEP Time
([:smoutput'parent'[])`([:exit 0:[:smoutput'child'[sleep)Fork 50 NB. start the child
([:exit 0:[:smoutput'child'[sleep)Fork 50 NB. start the child
parent
parent
i._2 3 4 NB. interactive computations continue in the parent process
i._2 3 4 NB. interactive computations continue in the parent process