Fork: Difference between revisions
Content added Content deleted
m (insert j solution) |
|||
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. |
|||
<lang J> |
|||
load'dll' |
|||
Fork =: @.(0='/lib/x86_64-linux-gnu/libc-2.19.so __fork > x' cd [: i. 0&[) |
|||
</lang> |
|||
The child process explicitly exits, with the child remaining as a zombie process until the parent terminates. |
|||
<pre> |
|||
NB. interactive session demonstrating Fork |
|||
Time =: 6!: |
|||
SLEEP =: 3 |
|||
sleep =: SLEEP Time |
|||
([:smoutput'parent'[])`([:exit 0:[:smoutput'child'[sleep)Fork 50 NB. start the child |
|||
parent |
|||
i._2 3 4 NB. interactive computations continue in the parent process |
|||
12 13 14 15 |
|||
16 17 18 19 |
|||
20 21 22 23 |
|||
0 1 2 3 |
|||
4 5 6 7 |
|||
8 9 10 11 |
|||
NB. zzzzz 50 seconds elapse, the child finishes. |
|||
child |
|||
</pre> |
|||
=={{header|Java}}== |
=={{header|Java}}== |