|
|
Line 156: |
Line 156: |
|
GP scripts cannot run in this fashion directly, but can be compiled into PARI code with <code>gp2c</code>. PARI code, whether from <code>gp2c</code> or not, can be run as a daemon just as [[#C|C]] would be. |
|
GP scripts cannot run in this fashion directly, but can be compiled into PARI code with <code>gp2c</code>. PARI code, whether from <code>gp2c</code> or not, can be run as a daemon just as [[#C|C]] would be. |
|
|
|
|
|
=={{header|Perl 6}}== |
|
=={{header|PicoLisp}}== |
|
⚫ |
<lang PicoLisp>(unless (fork) |
|
⚫ |
|
|
⚫ |
(println *Pid) # First write the daemon's PID to the file |
|
⚫ |
(for N 3600 # Write count for about one hour (if not killed) |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
(bye) ) # Child terminates after one hour |
|
|
|
|
⚫ |
(bye) # Parent terminates immediately</lang> |
|
|
|
|
⚫ |
|
|
⚫ |
<code>__FILE__</code> is a preprocessor definition that contains the current filename. |
|
⚫ |
if the first argument is "daemon" the program will be restarted with stdout redirected to "foo". |
|
|
|
|
⚫ |
<lang Pike>int main(int argc, array argv) |
|
⚫ |
|
|
⚫ |
if (sizeof(argv)>1 && argv[1] == "daemon") |
|
⚫ |
|
|
⚫ |
Stdio.File newout = Stdio.File("foo", "wc"); |
|
⚫ |
Process.spawn_pike(({ __FILE__ }), ([ "stdout":newout ])); |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
((get-ffi-obj 'daemon #f (_fun _int _int -> _int)) 0 0) |
|
⚫ |
(with-output-to-file "/tmp/foo" |
|
⚫ |
(λ() (for ([i 10]) (displayln (random 1000)) (flush-output) (sleep 1)))) |
|
⚫ |
|
|
|
|
|
⚫ |
|
|
|
(formerly Perl 6) |
|
<lang perl6>#!/usr/bin/env perl6 |
|
<lang perl6>#!/usr/bin/env perl6 |
|
|
|
|
Line 225: |
Line 268: |
|
1 |
|
1 |
|
</pre> |
|
</pre> |
|
|
|
⚫ |
|
|
⚫ |
<lang PicoLisp>(unless (fork) |
|
⚫ |
|
|
⚫ |
(println *Pid) # First write the daemon's PID to the file |
|
⚫ |
(for N 3600 # Write count for about one hour (if not killed) |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
(bye) ) # Child terminates after one hour |
|
|
|
|
⚫ |
(bye) # Parent terminates immediately</lang> |
|
|
|
|
⚫ |
|
|
⚫ |
<code>__FILE__</code> is a preprocessor definition that contains the current filename. |
|
⚫ |
if the first argument is "daemon" the program will be restarted with stdout redirected to "foo". |
|
|
|
|
⚫ |
<lang Pike>int main(int argc, array argv) |
|
⚫ |
|
|
⚫ |
if (sizeof(argv)>1 && argv[1] == "daemon") |
|
⚫ |
|
|
⚫ |
Stdio.File newout = Stdio.File("foo", "wc"); |
|
⚫ |
Process.spawn_pike(({ __FILE__ }), ([ "stdout":newout ])); |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
((get-ffi-obj 'daemon #f (_fun _int _int -> _int)) 0 0) |
|
⚫ |
(with-output-to-file "/tmp/foo" |
|
⚫ |
(λ() (for ([i 10]) (displayln (random 1000)) (flush-output) (sleep 1)))) |
|
⚫ |
|
|
|
|
|
|
|
=={{header|Sidef}}== |
|
=={{header|Sidef}}== |