Fork: Difference between revisions

Content added Content deleted
Line 670: Line 670:
else:
else:
# child code</lang>
# child code</lang>

=={{header|Racket}}==

Looks like there are two popular things that people do for this task, so here
are both. First, run some subprocess independently of Racket:

<lang Racket>
#lang racket
(define-values [P _out _in _err]
(subprocess (current-output-port) (current-input-port) (current-error-port)
(find-executable-path "du") "-hs" "/usr/share"))
;; wait for process to end, print messages as long as it runs
(let loop () (unless (sync/timeout 10 P) (printf "Still running...\n") (loop)))
</lang>

Output:
<pre>
Still running...
Still running...
Still running...
...snip...
15G /usr/share
</pre>

Second, using fork() in its raw form, which is doable in racket, but as unsafe as you'd expect it to be:

<lang Racket>
#lang racket
(require ffi/unsafe)
(define fork (get-ffi-obj 'fork #f (_fun -> _int)))
(printf ">>> fork() => ~s\n" (fork))
</lang>

Output:
<pre>
>>> fork() => 23834
>>> fork() => 0
</pre>


=={{header|REXX}}==
=={{header|REXX}}==